move into superclass

This commit is contained in:
Eric House 2014-06-12 23:52:20 -07:00
parent 9cfacf6667
commit 26a8bf418f
3 changed files with 18 additions and 19 deletions

View file

@ -102,9 +102,7 @@ public class DictsDelegate extends ListDelegateBase
int lang = DictLangCache.getLangLangCode( m_context, langName );
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context, lang );
if ( null != dals ) {
for ( DictAndLoc dal : dals ) {
alist.add( dal );
}
alist.addAll( Arrays.asList(dals) );
}
}
m_listInfo = alist.toArray( new Object[alist.size()] );
@ -600,12 +598,7 @@ public class DictsDelegate extends ListDelegateBase
m_langs = DictLangCache.listLangs( m_activity );
Arrays.sort( m_langs );
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 );
setListAdapterKeepScroll( new DictListAdapter( m_activity ) );
m_selDicts = new HashMap<String, XWListItem>();
}

View file

@ -21,6 +21,7 @@ package org.eehouse.android.xw4;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
@ -55,4 +56,16 @@ public class ListDelegateBase extends DelegateBase {
{
return m_activity.getListView();
}
protected void setListAdapterKeepScroll( ListAdapter adapter )
{
ListView listView = getListView();
int pos = listView.getFirstVisiblePosition();
View child = listView.getChildAt( 0 );
int top = (null == child) ? 0 : child.getTop();
setListAdapter( adapter );
listView.setSelectionFromTop( pos, top );
}
}

View file

@ -216,13 +216,7 @@ public class RemoteDictsDelegate extends ListDelegateBase
private void mkListAdapter()
{
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 );
setListAdapterKeepScroll( new RDListAdapter() );
}
private void setTitleBar()
@ -373,9 +367,8 @@ public class RemoteDictsDelegate extends ListDelegateBase
for ( int ii = 0; ii < nLangs; ++ii ) {
alist.add( new Integer(ii) );
if ( m_expanded[ii] ) {
for ( DictInfo di : m_langInfo.get( m_langNames[ii] ) ) {
alist.add( di );
}
DictInfo[] dis = m_langInfo.get( m_langNames[ii] );
alist.addAll( Arrays.asList( dis ) );
}
}
m_listInfo = alist.toArray( new Object[alist.size()] );