listView当中有嵌套了有onClickListener的控件时ListView自身的onItemClick无响应的解决方案

时间:2023-03-09 03:57:17
listView当中有嵌套了有onClickListener的控件时ListView自身的onItemClick无响应的解决方案

Ref:http://www.cnblogs.com/bluestorm/archive/2013/03/24/2979557.html

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.

解决方案

在ListView要显示的Item的外层加上

android:descendantFocusability="blocksDescendants"