ExpandableListView Group View Expand Default
Asked Answered
S

4

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?

Semasiology answered 21/5, 2011 at 10:0 Comment(2)
You want to open 2 of the 5 groups when the list is loaded?Ceramal
yes. now i got solution.Semasiology
S
115

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

ExpandableListView Exlist;

Exlist.expandGroup(0);
Exlist.expandGroup(1);
Semasiology answered 31/5, 2011 at 9:29 Comment(4)
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!Molybdenum
how to make all list in expandableListview to expand?Pontias
Make sure you set this after setAdapter. and you need to set this with index equal time with headers.Olander
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 networkArlin
C
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);
Cowskin answered 24/6, 2012 at 7:59 Comment(5)
How can I expand 3 level expandableListView ?Swob
thanq yar...helped meFlooring
This answer is best as the group count might be dynamicLum
@CrazyLearner: No, the Op specifically asked for another scenario: 2 groups should be opened, not allPolyphonic
i try this solution.but in my expandable listview only first and inbetween two groups only expanded not all.how can i resolve it?Ldopa
C
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
Comely answered 27/2, 2017 at 15:36 Comment(0)
F
1

Perfect solution for expanding expandable listview

ExpandableListAdapter expandableListAdapter;
ExpandableListView expandableListView;

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

expandableListAdapter.notifyDataSetChanged();
Fade answered 4/3, 2019 at 5:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.