Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview单击并单击按钮_Android_Android Layout_Android Listview - Fatal编程技术网

Android Listview单击并单击按钮

Android Listview单击并单击按钮,android,android-layout,android-listview,Android,Android Layout,Android Listview,在我的应用程序中,我有listview。每个listview的项都有一个按钮 当我按下按钮时,MClick按钮的状态也会改变 这是我的密码 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_gl"/> <item andro

在我的应用程序中,我有listview。每个listview的项都有一个按钮

当我按下按钮时,MClick按钮的状态也会改变

这是我的密码

<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>

这是我的listview项目按钮

 <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的项时,button总是改变他的状态

您指出,在选择列表项时,您的按钮会改变状态,这种行为是不受欢迎的。我认为这可能是因为这一行:

   <item android:state_selected="true" android:drawable="@drawable/ph_prod_button_gl"/>

如果选中该项目,则选中包含的按钮。 你试过移除它吗?
让我知道这是否有效。

我已经尝试了您的代码,并且在我的listview中运行良好。没有意外的状态更改。在我的测试中,按钮以focused=“false”项开始,如果我按下它,它将与状态_pressed=“true”匹配。如果单击该项目,则不会得到任何更改。你可以发布按钮样式和按钮的上下文吗?奇怪的是,它不仅仅在Nexus s(2.3.7)这样的旧设备上工作