Skip to main content

How to show only one child of expandable list at a time?

If you have "ExpandableListView" and show only one child of expandable Listview at a time, then below is the code for it.

     expendListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {  
           int previousGroup = -1;  
           @Override  
           public void onGroupExpand(int groupPosition) {  
             if(groupPosition != previousGroup)  
               expendListView.collapseGroup(previousGroup);  
             previousGroup = groupPosition;  
           }  
         });  
    

    "groupPosition" will return the open group id. So when I expand the other group then open group will collapse.

    You can also expand specific item of "ExpandableListView" by applying following code:

     expendListView.expandGroup(i);  
    



    Comments

    Post a Comment