ListView OnItemClickListener is not listening

巧了我就是萌 提交于 2019-12-02 11:39:06

If any row item of list contains focusable or clickable view then OnItemClickListener won't work such as for checkbox or button etc in the row item.There are two solution:

1. row item must be having param like android:descendantFocusability="blocksDescendants"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:descendantFocusability="blocksDescendants"
    android:gravity="center_vertical" >

    // your other widgets here

</LinearLayout>

2. Set given two attributes to false like

 android:focusable="false"
   android:focusableInTouchMode="false"

For example if there is any checkbox or button or image in the row item then

<CheckBox
    android:id="@+id/fav_check_box"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!