In the development often need to customize the ListView, to inherit the Baseadapter, in adapter in accordance with the requirements of the writing, the problem arises, there may be clicks on each item when there is no response, unable to get the focus.
Suppose you have a button in your own definition ListViewItem, ImageButton or a checkable control, the default focus is given to the child control, and the ListView item can be selected based on its ability to get focus.
So often when clicking on item changes the child control, the item itself is clicked without responding.
At this point, you can use the Descendantfocusability property to solve, he can set a control how to handle touch events,
This property is defined as the relationship between ViewGroup and its child controls when one gets the focus for the view.
There are three types of values for the property:
Android:descendantfocusability= "Blocksdescendants"//viewgroup overrides the subclass control and gets the focus directly android:focusable= "false" Android: Descendantfocusability= "Beforedescendants"//viewgroup takes precedence over its subclass control and gets to focus android:descendantfocusability= " Afterdescendants " //viewgroup only gets focus when its subclass control does not need to get focus
So we can solve this by setting its android:descendantfocusability= "Blocksdescendants" to the root control of item layout. This way, the item layout blocks all child controls from getting focus, so they can respond smoothly to the Onitenclick () method in Onitemclicklistener.
====================================================================================
Ouyangpeng welcome reprint, sharing with people is the source of progress!
Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng
====================================================================================
My Android Step-by-step tour------> An issue in which the Click event of item does not work when the nested (ListView) control in a ListView in Android is a workaround