0
在我的应用程序中,我有listview。每个listview的项目都有按钮。Listview OnItemClick和按钮
当我按onItemClick按钮的状态也改变了。
这里是我的代码
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/button_gl"/>
<item android:state_selected="true" android:drawable="@drawable/button_gl"/>
<item android:state_enabled="false" android:drawable="@drawable/button_unselect"/>
<item android:state_focused="false" android:drawable="@drawable/prod_button"/>
<item android:drawable="@drawable/prod_button"/>
</selector>
,这是我的列表视图项按钮
<Button
android:id="@+id/productAdd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/button_style"
android:background="@drawable/button_indicator"
android:layout_gravity="center_vertical"
android:gravity="center"
android:focusable="false"
android:focusableInTouchMode="false"/>
我不明白我做错了什么在这里,为什么总是得到按钮改变了他的状态,当我按Listview的项目?
不,它不起作用 – pmb
我试过你的代码,它在我的listview中效果很好。没有不希望的状态改变。在我的测试中,按钮的焦点=“false”项目开始,如果按下它,它会匹配state_pressed =“true”。如果我点击该项目,我没有任何变化。你可以发布按钮样式和按钮的上下文吗? –
奇怪的是,它不适用于像Nexus s(2.3.7) – pmb