我有一個ExpandableListActivity(使用SimpleCursorTreeAdapter),它在用戶單擊子元素時啓動另一個活動。在新活動中按下後退按鈕時,所有列表項都會再次摺疊。如何保存ExpandableListActivity的展開狀態並重新恢復。保存並恢復ExpandableListActivity的展開/摺疊狀態
我已經嘗試過的onSaveInstanceState實現的()和onRestoreInstanceState()這樣的...
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Parcelable listState = getExpandableListView().onSaveInstanceState();
outState.putParcelable("ListState", listState);
}
@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
Parcelable listState = state.getParcelable("ListState");
getExpandableListView().onRestoreInstanceState(listState);
}
...但onRestoreInstanceState()獲取從來沒有所謂。我也嘗試在onCreate()方法中恢復狀態,但它不會被調用:
if (savedInstanceState != null) {
Parcelable listState = savedInstanceState.getParcelable("ListState");
getExpandableListView().onRestoreInstanceState(listState);
}
我在做類似的位置http://stackoverflow.com/questions/10611927/simplecursortreeadapter-and-cursorloader – toobsco42 2012-05-16 07:22:12
@ toobsco42我不明白這是怎麼涉及到的東西問題 – Tom 2012-05-16 08:39:38
當返回到先前的活動時,請小心再次設置適配器。重新設置適配器將摺疊列表。 – jayeffkay 2013-05-08 10:30:25