Button preemption Focus issue in ListView

Source: Internet
Author: User

解决办法
Item xml 根节点添加 android:descendantFocusability="blocksDescendants"Button 设置android:focusable="false"这样点击Button 和ListView Item 可以分别响应自己的点击事件

 A common problem in development is that a ListView in a project is more than simply text, and often requires itself to define a ListView, Own adapter to inherit Baseadapter, in adapter in accordance with the requirements of the writing, the 
problem arises, may occur when clicking on each item when there is no response, unable to get the focus.
The reason for this is mostly due to the existence of Imagebutton,button in the item of your own definition, The child controls such as the checkbox, which can also be button or checkable, are then taken to the focus,
so it is often the child controls that change when the item is clicked, The click of the item itself is not responding. You can use descendantfocusability to solve this. This property is defined as the relationship between the ViewGroup and its child controls when a view gets focus. There are three values for the property: Beforedescendants:viewgroup takes precedence over its subclass control and gets to focus Afterdescendants:viewgroup gets the focus only if its subclass control does not need to get focus BL Ocksdescendants:viewgroup overrides the subclass control and gets the focus directly usually we use the third one, the root layout of the >item layout in
 

Button preemption Focus issue in 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.