Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapse all group except selected group in expandable listview android

I'm developing android application using expandable list view. Actually what I need is, I'm listing group, which contains child.

If I select an unexpandable group, it should expand, after I ll select second group at that time the first group should be collapsed. I did Google, but I couldn't find what I want. Please help me out.

like image 692
Sathish Avatar asked Jul 11 '13 06:07

Sathish


1 Answers

Have the current expanded group position stored in a variable. In onGroupExpanded do the following.

private int lastExpandedPosition = -1; private ExpandableListView lv; //your expandable listview ...  lv.setOnGroupExpandListener(new OnGroupExpandListener() {      @Override     public void onGroupExpand(int groupPosition) {             if (lastExpandedPosition != -1                     && groupPosition != lastExpandedPosition) {                 lv.collapseGroup(lastExpandedPosition);             }             lastExpandedPosition = groupPosition;     } }); 
like image 70
user936414 Avatar answered Sep 22 '22 03:09

user936414