Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List item with CheckBox not clickable

Tags:

I have a list item which contains a CheckBox, and I want to be able to click on the CheckBox and on the list item itself. Unfortunately, there seems to be some sort of conflict between the two, as I can only click on the item when I comment out the CheckBox. It seems like I recall there was a way to fix this, but I can't find it at the moment. Thanks

EDIT: This is with a ListFragment, so there's no need to call setOnItemClickListener.

OK, here's the XML for the list item. The problem is the CheckBox, but I figured might as well copy everything.

<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/list_item_survey"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     style="@style/SimpleListItem">     <TextView         android:id="@+id/survey_title"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         style="@style/ListItemTitle" />     <TextView         android:id="@+id/survey_date"         android:layout_below="@id/survey_title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         style="@style/ListItemSubtitle" />     <TextView         android:id="@+id/survey_completed"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentRight="true"         android:layout_below="@id/survey_title"         android:textColor="@color/accent_1"         android:text="@string/survey_completed"         style="@style/ListItemSubtitle" />     <CheckBox         android:id="@+id/survey_did_not_attend"         android:layout_below="@id/survey_date"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/survey_did_not_attend"         android:focusable="false"         style="@style/ListItemSubtitle" />  </RelativeLayout> 
like image 495
Shawn Lauzon Avatar asked Aug 04 '11 04:08

Shawn Lauzon


2 Answers

You need to add this to your custom adapter xml file android:descendantFocusability="blocksDescendants"

like image 97
Sunil Avatar answered Nov 02 '22 23:11

Sunil


insert this into the root element of the item row xml file

android:descendantFocusability="blocksDescendants" 
like image 27
sarankumar Avatar answered Nov 03 '22 00:11

sarankumar