Search code examples
androidexpandablelistview

expand all view when activity is load in ExpandableListView


My problem is...
I use Expandable list view in my activity. When the activity created it shows all the child group is collapsed. I would like to expand all children while the expandable list view is populated.
like

for that, I used below code in getGroupView() method adapter class

ExpandableListView eLV = (ExpandableListView) parent         
eLV.expandGroup(groupPosition,true);

now the groups are expanded but it can not allow me to collapse by clicking on the group header.


Solution

  • Simply add groupClickListener and return true for disabling collapse the child list. Add this code to your activity.

    yourExpandableList.setOnGroupClickListener(new OnGroupClickListener() {
      @Override
      public boolean onGroupClick(ExpandableListView parent, View v,
                                  int groupPosition, long id) { 
        return true; // This way the expander cannot be collapsed
      }
    });