My Android advanced tour ------> solution to the problem that the item click event cannot be performed when the ListView is nested (ListView) Control in Android, androidlistview
During development, you often need to define the Listview by yourself to inherit the BaseAdapter and write it as needed. The problem arises and may not respond when you click every item, cannot obtain the focus.
If your custom ListViewItem contains buttons,ImageButtonOr the Checkable subclass control, the default focus is handed over to the child control, and the basis for the ListView Item to be selected is that it can get the Focus.Therefore, when you click an item, the Sub-control is changed. The item's click does not respond.
In this case, you can use the descendantFocusability attribute to solve the problem. You can set a control to handle touch events,
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:
Android: descendantFocusability = "blocksDescendants" // viewgroup directly obtains the focus android: focusable = "false" android: descendantFocusability = "beforeDescendants" // viewgroup gets the focus android: descendantFocusability = "afterDescendants" from its subclass control first. // viewgroup gets the focus only when its subclass control does not need focus.
Therefore, we can solve this problem by setting the android: descendantFocusability = "blocksDescendants" of the root control of Item Layout. In this way, Item Layout shields all child controls from obtaining the Focus permission, in this way, you can smoothly respond to the onItenClick () method in onItemClickListener.
========================================================== ========================================================== ============================
Author: Ouyang Peng: Welcome to repost. sharing with others is the source of progress!
Reprinted Please retain the original address: http://blog.csdn.net/ouyang_peng
========================================================== ========================================================== ============================
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.