Android ListView Click Item No response solution _android

Source: Internet
Author: User

If the ListItem includes a button or a checkbox, the ListItem loses focus by default, causing the event that cannot respond to the item. The most common solution is to set the Descendantfocusability property in the ListItem layout file.

Item's Layout file:

<?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 "Androi D: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_ite" M_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" a Ndroid:layout_centervertical= "true" android:text= "edit" android:textcolor= "#ffffff" android:textsize= "14sp" Android: background= "@drawable/button_bg" > </Button> <textview android:id= "@+id/history_item_time_tv" android:l Ayout_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:la yout_toleftof= "@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 "a Ndroid:textcolor= "#565C5D" android:textsize= "14sp" android:text= "xxxxxxxxxxxxxxxxxxxxxxxx" android:ellipsize= "end "android: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 while looking for a View to take focus.

Must be one of the following constant values.

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

We're 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.