【发布时间】:2013-12-10 17:11:25
【问题描述】:
我有一个Activity,它使用了几个Fragments。我的一个片段有一个ExpandableListView,它使用了一个自制的Adapter。当屏幕方向改变时,保留(或我应该保留)和重新创建/保留的好策略是什么:
- Activity 中
Fragment的引用 -
片段中的
ExpandableListView -
ExpandableListView的状态(例如折叠/打开的组)
我目前正在做的是:每次都在Fragment 中重新创建Fragment、Adapter、ExpandableListView。 (还没有保存状态,但我想我会使用SharedPreferences)。
PS:减去选民:请详细说明我做错了什么。显然我遗漏了一些要点。
【问题讨论】:
-
您不应该使用
SharedPreferences来执行此操作。 -
试试
putFragment和getFragment/restoreFragment在这里查看我的答案:stackoverflow.com/questions/20189151/…
标签: android android-fragments expandablelistview