A common problem in development is that the listview in a project is not just a simple text, but you often need to define your own listview, and your own Adapter will inherit the BaseAdapter and write it as needed, the problem may occur. When you click an item, the system does not respond and cannot obtain the focus. Most of the reasons are that sub-controls such as ImageButton, Button, and CheckBox exist in your own defined items (also called the sub-Control of Button or Checkable ), at this time, these child controls will get the focus, so when you click an item, the Child control is changed, and the click of the item itself has no response.
In this case, descendantFocusability can be used to solve the problem. The API description is as follows:
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.
This attribute defines the relationship between the viewGroup and its child controls when the view gets the focus.
There are three types of attribute values:
BeforeDescendants: viewgroup takes precedence over its subclass control and obtains the focus.
AfterDescendants: viewgroup obtains the focus only when its subclass control does not need to obtain the focus.
BlocksDescendants: viewgroup overwrites the subclass control and directly obtains the focus.
We usually use the third type, that is, add the root layout of the Item layout.Android: descendantFocusability = "blocksDescendants".