Is it possible to preserve ExpandableListView's default list item press behavior when supplying a group view that contains more than just a TextView. The behavior I'm referring to is where the item being pressed changes background color to yellow.

Every time I supply a group view that contains e.g. a TextView and a Button, I lose the behavior.

2

There are 2 answers

1
Julian A. On

Including any view that is focusable within a custom list item layout will cause the list item to stop responding to presses. When implementing this sort of custom view, the focusable property of each view within the list item view must be set to false. This can be done either in xml or code. With one exception - ImageButton will not respond to setting its focusable field via xml. It only works in code with ImageButton.

<TextView
    android:id="@+id/text1"
    android:focusable="false"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Or

imageButtonInstance.setFocusable(false);
0
randr0id On

Another option is setting your root ViewGroup to block focus for child views.

Example: <LinearLayout ... android:descendantFocusability="blocksDescendants" />