My Android advanced tour ------ & gt; solution to the problem that the item click event cannot be performed when the ListView is nested (ListView) Control in Android, androidlistview

Source: Internet
Author: User

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.

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.