My Android Step-by-step tour------> Solution to an issue where item's Click event does not work when nested (ListView) control in ListView in Android

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.