Android ListView Item Click Unresponsive Workaround

Source: Internet
Author: User

If a control such as a button or a checkbox is included in the ListItem, by default ListItem loses focus, resulting in an event that cannot respond to item, the most common solution

is in the Descendantfocusability property is set in the ListItem layout file.

The layout file for item:

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/  Android "Android:layout_width=" Wrap_content "android:layout_height=" wrap_content "android:paddingtop=" 10DP " Android:paddingbottom= "10DP" android:paddingleft= "5DP" android:paddingright= "5DP" android:descendantfocusability= "Blocksdescendants" ><!--Add this property--<checkbox android:id= "@+id/history_item_checkbt" Android:layout_ height= "30DP" android:layout_width= "Wrap_content" android:layout_centervertical= "true" Android:layout_ Alignparentleft= "true" android:checked= "false" > </CheckBox> <imageview android:id= "@+id/history_item_ Image "Android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:layout_centervertical=" True "android:layout_torightof=" @id/history_item_checkbt "android:background=" @drawable/item_icon "> </ imageview> <button android:id= "@+id/history_item_edit_bt" Android:layoUt_alignparentright= "true" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android: Layout_centervertical= "true" android:text= "edit" android:textcolor= "#ffffff" android:textsize= "14SP" Android:backgro und= "@drawable/button_bg" > </Button> <textview android:id= "@+id/history_item_time_tv" Android:layout_ Width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centervertical= "true" android:textColor= "#565C5D" android:textsize= "14sp" android:text= "10-01 10:20" android:layout_marginright= "5DP" Android:layout_tolef tof= "@id/history_item_edit_bt" > </TextView> <textview android:id= "@+id/history_item_title_tv" Android: layout_height= "Wrap_content" android:layout_width= "Fill_parent" android:layout_centervertical= "true" Android: Textcolor= "#565C5D" android:textsize= "14sp" android:text= "xxxxxxxxxxxxxxxxxxxxxxxx" android:ellipsize= "End" Androi d:maxlines= "1" android:layout_torightof= "@id/History_item_image "android:layout_toleftof=" @id/history_item_time_tv "android:layout_marginleft=" 3DP "> </ Textview></relativelayout>

android:descendantfocusability

Defines the relationship between the ViewGroup and its descendants when looking-a View to take focus.

Must be one of the following constant values.

This property is defined as the relationship between ViewGroup and its child controls when one gets the focus for the view.

There are three types of values for the property:

Beforedescendants:viewgroup takes precedence over its subclass control and gets to focus

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

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

We are using the third one.

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.