Nikhil
Nikhil

Reputation: 16196

ExpandableListView Group View Expand Default

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?

Upvotes: 43

Views: 55669

Answers (4)

Jose
Jose

Reputation: 39

Perfect solution for expanding expandable listview

ExpandableListAdapter expandableListAdapter;
ExpandableListView expandableListView;

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

expandableListAdapter.notifyDataSetChanged();

Upvotes: 1

Kishore Reddy
Kishore Reddy

Reputation: 2454

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

Upvotes: 6

bhekman
bhekman

Reputation: 3277

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

Upvotes: 78

Nikhil
Nikhil

Reputation: 16196

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

ExpandableListView Exlist;

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

Upvotes: 115

Related Questions