Programmatically collapse a group in ExpandableListView

后端 未结 5 603
無奈伤痛
無奈伤痛 2020-11-28 21:55

When I expand a new group, can I collapse the last one expanded?

5条回答
  •  时光取名叫无心
    2020-11-28 22:39

    Try putting this in your ExpandableListAdapter, listView is a reference to the ExpandableListView itself. And lastExpandedGroupPosition is a integer member variable defined inside your ExpandableListAdapter.

        @Override
        public void onGroupExpanded(int groupPosition){
            //collapse the old expanded group, if not the same
            //as new group to expand
            if(groupPosition != lastExpandedGroupPosition){
                listView.collapseGroup(lastExpandedGroupPosition);
            }
    
            super.onGroupExpanded(groupPosition);           
            lastExpandedGroupPosition = groupPosition;
        }
    

提交回复
热议问题