Home » Android » ExpandableListView Group View Expand Default

ExpandableListView Group View Expand Default

Posted by: admin February 23, 2018 Leave a comment

Questions:

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?

Answers:

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

ExpandableListView Exlist;

Exlist.expandGroup(0);
Exlist.expandGroup(1);

Questions:
Answers:

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);

Questions:
Answers:

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