Custom ListView click issue on items in Android

Solution 1:

The issue is that Android doesn't allow you to select list items that have elements on them that are focusable. I modified the checkbox on the list item to have an attribute like so:

android:focusable="false"

Now my list items that contain checkboxes (works for buttons too) are "selectable" in the traditional sense (they light up, you can click anywhere in the list item and the "onListItemClick" handler will fire, etc).

EDIT: As an update, a commenter mentioned "Just a note, after changing the visibility of the button I had to programmatically disable the focus again."

Solution 2:

In case you have ImageButton inside the list item you should set the descendantFocusability value to 'blocksDescendants' in the root list item element.

android:descendantFocusability="blocksDescendants"

And the focusableInTouchMode flag to true in the ImageButton view.

android:focusableInTouchMode="true"

Solution 3:

I've had a similar issue occur and found that the CheckBox is rather finicky in a ListView. What happens is it imposes it's will on the entire ListItem, and sort of overrides the onListItemClick. You may want to implement a click handler for that, and set the text property for the CheckBox as well, instead of using the TextViews.

I'd say look into this View object as well, it may work better than the CheckBox

Checked Text View