diff --git a/src/com/android/email/activity/MailboxListFragment.java b/src/com/android/email/activity/MailboxListFragment.java index 9686a68a2..9dec6374c 100644 --- a/src/com/android/email/activity/MailboxListFragment.java +++ b/src/com/android/email/activity/MailboxListFragment.java @@ -20,7 +20,6 @@ import com.android.email.Controller; import com.android.email.Email; import com.android.email.R; import com.android.email.RefreshManager; -import com.android.email.activity.MailboxListFragment.Callback; import com.android.email.provider.EmailProvider; import com.android.emailcommon.Logging; import com.android.emailcommon.provider.EmailContent.Account; @@ -811,6 +810,16 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList } } + // Save list view state (primarily scroll position) + final ListView lv = getListView(); + final Parcelable listState; + if (mSavedListState != null) { + listState = mSavedListState; + mSavedListState = null; + } else { + listState = lv.onSaveInstanceState(); + } + if (cursor.getCount() == 0) { // There's no row -- call setListShown(false) to make ListFragment show progress // icon. @@ -840,12 +849,8 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList mDropTargetId = NO_DROP_TARGET; mDropTargetView = null; - // Restore the state. Need to do it manually so that the position will be restored - // even after orientation changes. - if (mSavedListState != null) { - getListView().onRestoreInstanceState(mSavedListState); - mSavedListState = null; - } + // Restore the list state. + lv.onRestoreInstanceState(listState); mIsFirstLoad = false; } diff --git a/src/com/android/email/activity/MessageListFragment.java b/src/com/android/email/activity/MessageListFragment.java index a72173308..28d565211 100644 --- a/src/com/android/email/activity/MessageListFragment.java +++ b/src/com/android/email/activity/MessageListFragment.java @@ -1220,6 +1220,16 @@ public class MessageListFragment extends ListFragment // Suspend message notifications as long as we're resumed adjustMessageNotification(false); + // Save list view state (primarily scroll position) + final ListView lv = getListView(); + final Parcelable listState; + if (mSavedListState != null) { + listState = mSavedListState; + mSavedListState = null; + } else { + listState = lv.onSaveInstanceState(); + } + // If this is a search mailbox, set the query; otherwise, clear it if (mMailbox != null && mMailbox.mType == Mailbox.TYPE_SEARCH) { mListAdapter.setQuery(mMailbox.mDisplayName); @@ -1246,10 +1256,7 @@ public class MessageListFragment extends ListFragment // Restore the state -- this step has to be the last, because Some of the // "post processing" seems to reset the scroll position. - if (mSavedListState != null) { - getListView().onRestoreInstanceState(mSavedListState); - mSavedListState = null; - } + lv.onRestoreInstanceState(listState); // Clear this for next reload triggered by content changed events. mIsFirstLoad = false;