如何保存和恢复在Android中的ExpandableListView的状态? [英] How to save and restore the state of an ExpandableListView in Android?
问题描述
是否可以保存和恢复状态的Android的ExpandableListView(这项目晕倒,这不是)?
Is it possible to save and restore the state (which items are collapsed and which not) of an ExpandableListView in Android?
如果有可能,我该怎么办呢?
If it is possible, how can I do that?
我可以,我可以访问ExpandableListView中的onPause()/ onResume()又如何呢?
Can I can I access the ExpandableListView in onPause() / onResume() and how?
推荐答案
我遍历组并保存它们的状态:
I iterate through the groups and save the state of them all:
int numberOfGroups = MyExpandableListViewAdapter.getGroupCount();
boolean[] groupExpandedArray = new boolean[numberOfGroups];
for (int i=0;i<numberOfGroups;i++)
groupExpandedArray[i] = MyExpandableListView.isGroupExpanded(i);
那么对于恢复状态:
Then for restore the state:
for (int i=0;i<groupExpandedArray.length;i++)
if (groupExpandedArray[i] == true)
MyExpandableListView.expandGroup(i);
我不明白你如何访问的onPause()/ onResume()在ListView的意思是,如果你的ListView的对象存储为活动类的成员应该是可从那里。
I don't understand what you mean by how to access the ListView in onPause() / onResume(), it should be accessible from there if you store the ListView object as a member of the activity class.
这篇关于如何保存和恢复在Android中的ExpandableListView的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!