Listviewbutton indicates the focus of a button in listview.

Source: Internet
Author: User

Listviewbutton indicates the focus of a button in listview.

Solution
Add android: descendantFocusability = "blocksDescendants" Button to android: focusable = "false" to the root node of Item xml. In this way, click "Button" and "ListView Item" to respond to their click events respectively.

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 ), in this case, these child controls obtain the focus,
Therefore, when you click an item, the Sub-control is changed. The item's click does not respond. In this case, descendantFocusability can be used to solve the problem. This attribute defines the relationship between viewGroup and its child controls when a view obtains the focus. Three attribute values are available: beforeDescendants: viewgroup takes precedence over its subclass control and obtains focus afterDescendants: viewgroup obtains focus blocksDescendants only when its subclass control does not need focus: viewgroup will overwrite the subclass control and directly obtain the focus. Usually we use the third type, that is, add ** android: the attribute of descendantFocusability = "blocksDescendants" ** is ready, so far the flexibility event clicked by listview has come to an end.

 

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.