From f375defc0bb319b1dc0773c44b3833eb01a7450f Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 12 Jun 2014 06:51:17 -0700 Subject: [PATCH] preserve scroll position across recreation of list adapters --- .../src/org/eehouse/android/xw4/DictsDelegate.java | 10 +++++++--- .../org/eehouse/android/xw4/RemoteDictsDelegate.java | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java index cbe63f982..de0231076 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java @@ -71,7 +71,6 @@ public class DictsDelegate extends ListDelegateBase private String m_downloadStr; private ListView m_listView; private String[] m_locNames; - private DictListAdapter m_adapter; private HashMap m_selDicts; private String m_origTitle; @@ -600,8 +599,13 @@ public class DictsDelegate extends ListDelegateBase { m_langs = DictLangCache.listLangs( m_activity ); Arrays.sort( m_langs ); - m_adapter = new DictListAdapter( m_activity ); - m_activity.setListAdapter( m_adapter ); + + int pos = m_listView.getFirstVisiblePosition(); + View child = m_listView.getChildAt( 0 ); + int top = (child == null) ? 0 : child.getTop(); + + setListAdapter( new DictListAdapter( m_activity ) ); + m_listView.setSelectionFromTop( pos, top ); m_selDicts = new HashMap(); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RemoteDictsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RemoteDictsDelegate.java index 18cbde577..221281671 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RemoteDictsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RemoteDictsDelegate.java @@ -47,7 +47,6 @@ public class RemoteDictsDelegate extends ListDelegateBase implements GroupStateListener, SelectableItem, DwnldDelegate.DownloadFinishedListener { private ListActivity m_activity; - private ListView m_listView; private boolean[] m_expanded; private String[] m_langNames; private static enum DictState { AVAILABLE, INSTALLED, NEEDS_UPDATE }; @@ -74,7 +73,6 @@ public class RemoteDictsDelegate extends ListDelegateBase protected void init( Bundle savedInstanceState ) { setContentView( R.layout.remote_dicts ); - m_listView = getListView(); JSONObject params = new JSONObject(); // empty for now m_origTitle = getTitle(); @@ -186,8 +184,13 @@ public class RemoteDictsDelegate extends ListDelegateBase private void mkListAdapter() { - RDListAdapter adapter = new RDListAdapter(); - setListAdapter( adapter ); + ListView listView = getListView(); + int pos = listView.getFirstVisiblePosition(); + View child = listView.getChildAt( 0 ); + int top = (child == null) ? 0 : child.getTop(); + + setListAdapter( new RDListAdapter() ); + listView.setSelectionFromTop( pos, top ); } private void setTitleBar()