How to preserve scroll position in an ExpandableListView
<p>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.</p>

<p>Solution 1:</p>

<pre><code>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);
}
</code></pre>

<p>Solution 2:</p>

<pre><code>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);
}
</code></pre>

<p>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</p>

<p>Anyone can suggest a good way to achieve my goal?</p>
