如何保持ExpandableListView在扩展状态?状态、ExpandableListView

2023-09-05 07:13:56 作者:月亮凑过来听

我用

SimpleExpandableListAdapter

SimpleExpandableListAdapter

在我的

ExpandableListActivity

ExpandableListActivity

当用户单击该组所在的行,孩子们列表展开并显示,当用户单击展开列表中的每个子项,用户将被导航到下一个second_Activity。目前,当用户单击后退按钮返回从second_Activity到ExpandableListActivity,可扩展列表被初始化为未膨胀的,我想扩展列表保持扩张状态,让用户知道previously他有哪些项目选中。如何做到这一点?哪种方法从ExpandableListActivity应该重写?

When user click the group row, the children list is expanded and show, when user click each child item in the expanded list, user will be navigated to the next second_Activity. Currently, when user click the back button to go back from second_Activity to the ExpandableListActivity, the expandable list is initialized as un-expanded, I would like the expandable list keep in expanded status, so that user know previously which item he has selected. How to do that? Which method from ExpandableListActivity should be override?

PS:我知道我应该把 getExpandableListView()expandGroup(groupPosition); 的地方,哪来?我试图把这个code。在 onGroupClick() onChildClick(),但这并没有帮助。

PS: I know I should put getExpandableListView().expandGroup(groupPosition); somewhere, but where? I tried to put this code in onGroupClick() and onChildClick(), but this does not help.

推荐答案

有关始终扩展团体,我向SimpleExpandableListAdapter并设置组中的getGroupView方法加以扩充:

For always expanded groups, I extend SimpleExpandableListAdapter and set the group to be expanded in the getGroupView method:

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
    ExpandableListView eLV = (ExpandableListView) parent;
    eLV.expandGroup(groupPosition);
    return v;
}