I would like my ExpandableListView to only allow one group to be expanded at a time. I found a solution that does this by overriding the ListViewAdapter’s onGroupExpanded to method to collapse the previously expanded group:
@Override
public void onGroupExpanded(int groupPosition)
{
//collapse the old expanded group, if not the same
//as new group to expand
if(groupPosition != mLastExpandedGroup && mLastExpandedGroup != -1)
{
epView.collapseGroup(mLastExpandedGroup);
}
mLastExpandedGroup = groupPosition;
super.onGroupExpanded(groupPosition);
}
By default, when a new group is expanded the ListView is scrolled such that the GroupView for the new group remains visible. This scrolling doesn’t work properly for my customized ListView (often the GroupView for the newly expanded group ends up off screen).
Based on the android source, the reason this doesn’t work is because the post-expansion scroll position is determined prior the onGroupExpanded method being called, so the position is inaccurate after I force a group to collapse.
So, any suggestions for a custom ListView which allows only one group expanded at a time, and properly scrolls so that the GroupView is visible when a group is exapnded?
try calling the scroll function inside a
post()orpostDelayed()to make sure the scroll appears later than the default one.