(Android)listview with multiple buttons, list item can't be clicked

隐身守侯 提交于 2019-11-29 04:35:30

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!