ListView long click not working when a button is in list

做~自己de王妃 提交于 2019-12-05 06:41:51

Your image button is probably taking focus when you click on list item.

So Add this

android:descendantFocusability="blocksDescendants" 

to your root element

http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:descendantFocusability

android:descendantFocusability

Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.

Must be one of the following constant values.

Constant    Value   Description
beforeDescendants   0    The ViewGroup will get focus before any of its descendants.
afterDescendants    1    The ViewGroup will get focus only if none of its descendants want it.
blocksDescendants   2    The ViewGroup will block its descendants from receiving focus.
This corresponds to the global attribute resource symbol descendantFocusability.

did you set the android:longClickable="true" in the xml and the listview.setLongClickable(true); in the code ?

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