Use the button workaround in Android listview

Source: Internet
Author: User

In fact, a lot of things are not paste code can be solved, do anything to do it attentively, so as to sleep at night more practical.

When you paste someone else's code, sometimes out of the bug is really annoying, but when you understand the point of principle, can see the essence of the problem, solve it is also very handy to start today's theme. When you see this problem, you should know where the problem is, and use the button in the ListView ( Of course not only button, but also ImageButton and other self-response click View, the problem arises, you will find the ListView item can not click, specifically because of what? Most of the reason is the focus, The button grabbed the item's focus so that item could not respond to the Click event, so how to fix it? The first protagonist of the Day (descendantfocusability) is going to be a shining debut ...

The android:descendantfocusability has three values, namely: beforedescendants,afterdescendants,blocksdescendants

1.android:descendantfocusability= "beforedescendants" means that the ListView item gets the focus first.

2.android:descendantfocusability= "afterdescendants" only button does not need focus when item gets focus

3.android:descendantfocusability= "Blocksdescendants" Item overrides button to get focus directly

See the effect of these three properties you should know how to solve the problem, the ListView and button when the focus of the grab I used to use the third, and then write the button in the adapter onclick event, so that everyone who do not provoke anyone, peace together.

Use the button workaround in Android listview

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.