Description of the problem: Define the listview by yourself, define the Adapter of l to inherit the BaseAdapter, there is no response when clicking on each item, and the focus cannot be obtained.
Cause of the problem: Mostly because there are sub-controls such as ImageButton, Button, CheckBox (also subclass controls of Button or Checkable) in the Item defined by you. At this time, these sub-controls will get the focus, so often When the item is clicked, it is the sub-control that changes, and the click of the item itself does not respond.
Solution:
add the attribute android:descendantFocusability="blocksDescendants"
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.
This property defines the relationship between the viewGroup and its child controls when a view gets focus.
There are three types of attribute values:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
To sum up, usually we use the third type, that is, add the attribute of android:descendantFocusability=”blocksDescendants” to the root layout of the Item layout.
For examples, please refer to: http://blog.csdn.net/lrxb_123/article/details/53068329In item attribute setting.