I have a class that extends ListFragment, and it overrides the OnListItemClick method. I am also doing this in another ListFragment the same way (and the method gets called)
Here is an elegant solution which allows onListItemClick
to fire the way you think it should, and also allows any child views to receive events (or not, depending on how you want to set it.) For the question posed, this would allow for keeping the checkbox subview. Please take care to consider whether this is an intuitive experience for users.
On the root ViewGroup of all list items, set the descendantFocusability
attribute in XML:
android:descendantFocusability="blocksDescendants"
Android SDK documentation of descendantFocusability. Has been part of the SDK since Android 1.0. Other settings for android:descendantFocusability
include "beforeDescendants"
and "afterDescendants"
.
Example cluster_layout.xml which sets descendantFocusability
(List items applied to cluster_list.xml via an ArrayAdapter):
Example cluster_list.xml, which has no bearing on this solution other than to show that it's intended for use in a ListFragment by having a ListView element with the id @id/android:list: