Reputation:
I am new to Android development. I followed this tutorial for showing ExpandableListView
and its working properly. If I press all group then all group will expand.
I want to expand only one group at a time. At the beginning, the first group will expand automatically and If I tap another group then the first group will collapse and the recent group will expand. Is it possible?
If possible then how can I get. Any suggestion?
Upvotes: 2
Views: 2940
Reputation: 2558
You may achieve using GroupExpandListener
.Store last Expanded position to variable and collapseGroup using this variable
private int lastPosition = -1;
private ExpandableListView lv; //your expandable listview
lv.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if (lastPosition != -1
&& groupPosition != lastPosition) {
lv.collapseGroup(lastPosition);
}
lastPosition = groupPosition;
}
});
Upvotes: 5