ListView with multiple buttons, list item can't be clicked

前端 未结 3 794
借酒劲吻你
借酒劲吻你 2020-12-18 04:32

I have a list with two buttons in it. When I want to click a list item it doesn\'t work, but my button is still clickable. How I can make all buttons include the ent

相关标签:
3条回答
  • 2020-12-18 05:13
    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout  android:id="@+id/rel1" android:layout_width="fill_parent"
            android:layout_height="wrap_content">
    
    <Button
            android:id="@+id/erase"
            android:layout_marginLeft="6dip"
            android:layout_marginTop="6dip"
            android:layout_width="40dip"
            android:layout_height="40dip"
            android:background="@drawable/closebtn"
            android:focusable="false"
            android:focusableInTouchMode="false"
        />
       <ImageButton android:id="@+id/soundf"
            android:layout_width="40dip"
            android:layout_height="40dip"
            android:layout_below="@+id/erase"
            android:layout_alignLeft="@+id/erase"
            android:background="@drawable/soundinv"
            android:focusable="false"
            android:focusableInTouchMode="false"
            /> 
       <TextView android:id="@+id/texxt1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/erase"
            android:layout_alignTop="@+id/erase"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#CC0"
       />
    
       <TextView android:id="@+id/texxt2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/texxt1"
            android:layout_alignLeft="@+id/texxt1"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#FFF"
       />
    </RelativeLayout>
    

    now you can also given click event to relative layout.

    0 讨论(0)
  • 2020-12-18 05:21

    For Buttons, Checkboxs and ImageViews:

    android:focusable="false"
    

    Now both (buttons and rows) of ListView are clickable.

    For ImageButtons, you have to set focusable while running, because the constructor of ImageButtons sets it to true. I recommend you using a ImageView instead of a ImageButton.

    0 讨论(0)
  • 2020-12-18 05:28

    Just add this to your Java code: holder.yourButton.setFocusable(false); I am using my own cursorAdapter so I am putting the line of code at the end of bindView this should do it.

    0 讨论(0)
提交回复
热议问题