Collapse all group except selected group in expandable listview android

后端 未结 8 957
故里飘歌
故里飘歌 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:42

    I also faced the same problem. But I could solved my problem by the following code:

    As I had 4 Headers in my expandable list, based on that i wrote like this

    expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
    
                @Override
                public void onGroupExpand(int groupPos) {
                    // TODO Auto-generated method stub
                    expListView.collapseGroup(groupPos+1);
                    expListView.collapseGroup(groupPos-1);
                    expListView.collapseGroup(groupPos-2);
                    expListView.collapseGroup(groupPos+2);
                    expListView.collapseGroup(groupPos+3);
                    expListView.collapseGroup(groupPos-3);
                }
            });`
    
    0 讨论(0)
  • 2020-12-23 09:43

    Get ExpendableListView and then override the following method - setOnGroupExpandListener

    expandableListView = (ExpandableListView) findViewById(R.id.exp_listview);
    
    expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            int previousItem = -1;
    
            @Override
            public void onGroupExpand(int groupPosition) {
                if (groupPosition != previousItem)
                    expandableListView.collapseGroup(previousItem);
                previousItem = groupPosition;
            }
        });
    
    0 讨论(0)
提交回复
热议问题