I want to make only one item in the parent list expand at a time, my code for the onCreate is currently the following. (It works as I want, But the method to allow only one pare
// Declare variable
private static int prev = -1;
// and OnGroupExpandListener implement
mExpandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if(prev!=-1)
{
mExpandableList.collapseGroup(prev);
}
prev=groupPosition;
}
});
Updating with updated solution
mExpandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
// Keep track of previous expanded parent
int previousGroup = -1;
@Override
public void onGroupExpand(int groupPosition) {
// Collapse previous parent if expanded.
if ((previousGroup != -1) && (groupPosition != previousGroup)) {
mExpandableList.collapseGroup(previousGroup);
}
previousGroup = groupPosition;
}
});