How can ExpandableListView's default list item

2019-05-07 03:08发布

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条回答
祖国的老花朵
2楼-- · 2019-05-07 03:29

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

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

查看更多
贼婆χ
3楼-- · 2019-05-07 03:45

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);
查看更多
登录 后发表回答