Collapse all group except selected group in expandable listview android

后端 未结 8 965
故里飘歌
故里飘歌 2020-12-23 09:20

I\'m developing android application using expandable list view. Actually what I need is, I\'m listing group, which contains child.

If I select an unexpandable group

8条回答
  •  暖寄归人
    2020-12-23 09:25

    If the ExpandableListView has more than 2 groups:

    expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            for (int g = 0; g < expandableListAdapter.getGroupCount(); g++) {
                if (g != groupPosition) {
                    expandableListView.collapseGroup(g);
                }
            }
        }
    });    
    

    It will collapse all groups except the clicked one.

提交回复
热议问题