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.