Manually restore list view state.

Bug 4532222

Change-Id: I6f3394b7ffd55b32e1932e3e425cc0d0ae720e27
This commit is contained in:
Makoto Onuki 2011-06-03 13:57:02 -07:00
parent d42b3222fb
commit 345a61d0b9
2 changed files with 23 additions and 11 deletions

View File

@ -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;
}

View File

@ -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;