43

I have develop ExpandableListView perfectly.

In My ExpandableListView five groups are there. load first time then collapse all five group. it is default.

now my question is load first time expandablelistview at that time 2 groups are expand and other 3 groups are collapse.

so please guide me how to do?

Nikhil
  • 16,194
  • 20
  • 64
  • 81

4 Answers4

116

Now I got solution and it will work perfectly.. Please use this..

ExpandableListView Exlist;

Exlist.expandGroup(0);
Exlist.expandGroup(1);
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
Nikhil
  • 16,194
  • 20
  • 64
  • 81
  • This works great! I wanted my first section to be expanded by default when the app started, so I simply added MyListName.expandGroup(0); into onCreate and it worked perfectly! Thank you! – LargeGlasses Nov 01 '13 at 18:00
  • how to make all list in expandableListview to expand? – Anuraj R Feb 22 '17 at 07:49
  • Make sure you set this after `setAdapter`. and you need to set this with index equal time with headers. – Rumit Patel Oct 08 '18 at 12:30
  • 1
    It doesnt matter where you put this code, before or after `setAdapter`. But you should put that after your set your data for adapter. This makes sens if you sets adapter and then loads your data over a network – Anatolii Shuba Aug 01 '21 at 19:35
78

I built this snippet based off Nikhil's answer. Thought others might find it useful as well. Only works if you are using BaseExpandableListAdapter. elv

ExpandableListView elv = (ExpandableListView) findViewById(R.id.elv_main);
elv.setAdapter(adapter);
for(int i=0; i < adapter.getGroupCount(); i++)
    elv.expandGroup(i);
Community
  • 1
  • 1
bhekman
  • 3,227
  • 21
  • 24
6

This is a perfect solution, it will increase automatically

ExpandableListView elv = (ExpandableListView) findViewById(R.id.elv_main);
elv.setAdapter(adapter);
for(int i=0; i < adapter.getGroupCount(); i++)
    elv.expandGroup(i);

but this is based on the item positions

ExpandableListView Exlist;
Exlist.expandGroup(0);// first item of listview
Exlist.expandGroup(1);//second item of listview
rogelio
  • 1,541
  • 15
  • 19
Kishore Reddy
  • 2,394
  • 1
  • 19
  • 15
1

Perfect solution for expanding expandable listview

ExpandableListAdapter expandableListAdapter;
ExpandableListView expandableListView;

expandableListView.expandGroup(0);
expandableListView.expandGroup(1);

expandableListAdapter.notifyDataSetChanged();
Andreas
  • 2,455
  • 10
  • 21
  • 24
Jose
  • 39
  • 5