Group list: Don't reset scroll position during sync
Manually call ListView.onSave/RestoreInstanceState to restore the scroll
position after setting a new adapter.
Note this solution isn't perfect; ListView.onSaveInstanceState saves
the item ID of the fist item (as well as offset to the scroll, etc).
The scroll position will only be restored correctly if the ID is valid
(i.e. non negative) and unique.
In our case, if the first item is a header, the list view will get
confused and may scroll to the wrong position. But it shouldn't be that
big deal here...
Change-Id: I07e2682178d068253ccc96bc7a836de4bd25c7ef
diff --git a/src/com/android/contacts/group/GroupBrowseListFragment.java b/src/com/android/contacts/group/GroupBrowseListFragment.java
index 59b0cec..db16502 100644
--- a/src/com/android/contacts/group/GroupBrowseListFragment.java
+++ b/src/com/android/contacts/group/GroupBrowseListFragment.java
@@ -32,6 +32,7 @@
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Parcelable;
import android.provider.ContactsContract.Groups;
import android.text.TextUtils;
import android.view.LayoutInflater;
@@ -227,6 +228,7 @@
mAdapter.setSelectionVisible(mSelectionVisible);
mAdapter.setSelectedGroup(mSelectedGroupUri);
+ Parcelable listState = mListView.onSaveInstanceState();
mListView.setAdapter(mAdapter);
mListView.setEmptyView(mEmptyView);
mListView.setOnItemClickListener(new OnItemClickListener() {
@@ -239,6 +241,9 @@
if (mSelectionToScreenRequested) {
requestSelectionToScreen();
+ } else {
+ // Restore the scroll position.
+ mListView.onRestoreInstanceState(listState);
}
if (mSelectionVisible && mSelectedGroupUri != null) {