Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand all children in expandable list view

I would like to expand all children while the expandable list view is populated. Currently my code looks like this:

ExpandableListView listView = (ExpandableListView) findViewById(R.id.view); int count = viewAdapted.getGroupCount(); for (int position = 1; position <= count; position++)     listView.expandGroup(position - 1); 

which is pretty ugly. Is there a nicer way to do this?

like image 940
Drejc Avatar asked Jul 29 '11 12:07

Drejc


People also ask

What is an Expandable list view?

A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view.

How to expand all the groups in ExpandableListView Android?

To do this, use the Expand and Collapse actions of the Android ExpandableList object that corresponds to the tested expandable list. You can expand or collapse all the groups of the list by setting the Group parameter to -1.


1 Answers

You can expand it in getGroupView in your custom adapter:

@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {     View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);     ExpandableListView mExpandableListView = (ExpandableListView) parent;     mExpandableListView.expandGroup(groupPosition);     return v; } 

Gluck!

like image 56
Justin Avatar answered Sep 21 '22 08:09

Justin