in my app I have a class derived from ExpandableListActivity. When I scroll the contents, and then change phone orientation or edit an item and then go back to the list, the original list position is not preserved. I have tried two solutions, similar to those I have recently successfully used with ListActivity-derived classes.
Solution 1:
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
mListState = state.getParcelable(LIST_STATE);
}
protected void onResume() {
super.onResume();
loadData();
if (mListState != null)
getExpandableListView().onRestoreInstanceState(mListState);
}
protected void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
mListState = getExpandableListView().onSaveInstanceState();
state.putParcelable(LIST_STATE, mListState);
}
Solution 2:
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
mListPosition = state.getInt(LIST_STATE);
}
protected void onResume() {
super.onResume();
loadData();
getExpandableListView().setSelection(mListPosition);
}
protected void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
mListPosition = getExpandableListView().getFirstVisiblePosition();
state.putInt(LIST_STATE, mListPosition);
}
Neither solution works. I have also tried to combine the two solutions, and this works when I edit an item and go back to the list, but it does NOT work when I change the phone orientation
Anyone can suggest a good way to achieve my goal?