I'm using ExpandableListView. i have a around 100 groups in the list, and 10-15 childrens for each group.
now my problem is, whenever i expand a new Group , i want the previously expanded group to be closed. is there a way to do this. Please anyone tell me whether it is possible to do thi开发者_C百科s..
Thank u
You can use the ExpandableListView.OnGroupExpandListener. Maintain the previously expanded groupPosition and use collapseGroup(groupPosition) to close the group.
Very well, we have to maintain previous group integer by final or static variable
expandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
int previousItem = -1;
@Override
public void onGroupExpand(int groupPosition) {
if(groupPosition != previousItem ) {
expandableList.collapseGroup(previousItem );
}
previousItem = groupPosition;
}
});
精彩评论