Click on list item of a ListView doesn't respond

妖精的绣舞 提交于 2019-11-30 15:12:17

You should define on all of the child objects in the item listview (TextView, ImageView etc.):

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

And for the root item RelativeLayout / LinearLayout and so, define:

android:clickable="false"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"

If you won't define those, they will "catch" the click event. And if you have a Custom listView adapter, just check that you override:

@Override
public boolean isEnabled(int position)
{
    return true;
}
CoolMind

In my case a problem was in fact that a ListView contained HorizontalScrollViews.

HSV consumes clicks over items and doesn't return OnItemClick to the ListView.

I solved the problem when wrote an OnClickListener inside an adapter that returns a callback to the ListView. See here: https://stackoverflow.com/a/43653085/2914140.

Yoozzii

In the customer Item,

set every element

android:clickable="true"
android:focusable="false"

works for me

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