Android: descendantFocusability Usage Analysis

Source: Internet
Author: User

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".

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.