2014-02-25 68 views
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的项目?

回答

0

你指出,在列表项选择时,你的按钮改变状态,这种行为是不希望的。我认为这可能是由以下行引起的:

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

如果还选中了所包含的按钮, 你试过删除它吗? 让我知道这是否工作。

+0

不,它不起作用 – pmb

+0

我试过你的代码,它在我的listview中效果很好。没有不希望的状态改变。在我的测试中,按钮的焦点=“false”项目开始,如果按下它,它会匹配state_pressed =“true”。如果我点击该项目,我没有任何变化。你可以发布按钮样式和按钮的上下文吗? –

+0

奇怪的是,它不适用于像Nexus s(2.3.7) – pmb