The solution of button preemption focus in ListView _android

Source: Internet
Author: User

Istview button preemption Focus Solution:

Item XML root node add android:descendantfocusability= "Blocksdescendants"

Button settings

Android:focusable= "false"

Click the button and ListView Item to respond to your own click events individually

Development of a very common problem, the project ListView not only simple text, often need to define their own ListView, their own adapter to inherit Baseadapter, in the adapter in accordance with the needs of the writing, the problem appeared, May occur when clicking on each item when there is no response and cannot get the focus.

Most of the reason is that there are child controls such as Imagebutton,button,checkbox (or a Button or checkable subclass control) in your own defined item, at which point the child controls get the focus, So often when you click on the item, the child controls change, and the item itself is clicked without responding.

Then you can use descendantfocusability to solve it.

This property is the relationship between the ViewGroup and its child controls when a view gets the focus.

The value of the property has three kinds:

Beforedescendants:viewgroup takes precedence over its child class controls and gets the focus

Afterdescendants:viewgroup gets focus only when its subclass control does not need to get focus

Blocksdescendants:viewgroup overrides the subclass control and gets the focus directly

Usually we use a third, that is, in the item layout of the root layout plus **android:descendantfocusability= "blocksdescendants" * * property is good, so listview click on the supernatural event.

The above is a small set to introduce the ListView button to seize the focus of the solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.