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 8b68049e9..3edc64969 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java @@ -176,7 +176,7 @@ public class DictsDelegate extends ListDelegateBase } // makeListData @Override - public View getView( Object dataObj ) + public View getView( Object dataObj, View convertView ) { View result = null; @@ -189,48 +189,53 @@ public class DictsDelegate extends ListDelegateBase boolean expanded = ! m_closedLangs.contains( langName ); String name = getString( R.string.lang_name_fmt, langName, info.m_numDicts ); - result = ListGroup.make( m_context, DictsDelegate.this, - groupPos, name, expanded ); - } else if ( dataObj instanceof DictAndLoc ) { - DictAndLoc dal = (DictAndLoc)dataObj; - XWListItem item = - XWListItem.inflate( m_activity, DictsDelegate.this ); - result = item; - - String name = dal.name; - item.setText( name ); - - DictLoc loc = dal.loc; - item.setComment( m_locNames[loc.ordinal()] ); - item.setCached( loc ); - - item.setOnClickListener( DictsDelegate.this ); - - // Replace sel entry if present - if ( m_selDicts.containsKey( name ) ) { - m_selDicts.put( name, item ); - item.setSelected( true ); - } - } else if ( dataObj instanceof DictInfo ) { - DictInfo info = (DictInfo)dataObj; - XWListItem item = - XWListItem.inflate( m_activity, DictsDelegate.this ); - result = item; - - String name = info.m_name; - item.setText( name ); - item.setCached( info ); - - item.setExpandedListener( DictsDelegate.this ); - item.setExpanded( m_expandedItems.contains( info ) ); - item.setComment( m_onServerStr ); - - if ( m_selDicts.containsKey( name ) ) { - m_selDicts.put( name, item ); - item.setSelected( true ); - } + result = ListGroup.make( m_context, convertView, + DictsDelegate.this, groupPos, name, + expanded ); } else { - Assert.fail(); + XWListItem item; + if ( null != convertView && convertView instanceof XWListItem ) { + item = (XWListItem)convertView; + } else { + item = XWListItem.inflate( m_activity, DictsDelegate.this ); + } + result = item; + + if ( dataObj instanceof DictAndLoc ) { + DictAndLoc dal = (DictAndLoc)dataObj; + + String name = dal.name; + item.setText( name ); + + DictLoc loc = dal.loc; + item.setComment( m_locNames[loc.ordinal()] ); + item.setCached( loc ); + + item.setOnClickListener( DictsDelegate.this ); + item.setExpandedListener( null ); // item might be reused + + // Replace sel entry if present + if ( m_selDicts.containsKey( name ) ) { + m_selDicts.put( name, item ); + item.setSelected( true ); + } + } else if ( dataObj instanceof DictInfo ) { + DictInfo info = (DictInfo)dataObj; + String name = info.m_name; + item.setText( name ); + item.setCached( info ); + + item.setExpandedListener( DictsDelegate.this ); + item.setExpanded( m_expandedItems.contains( info ) ); + item.setComment( m_onServerStr ); + + if ( m_selDicts.containsKey( name ) ) { + m_selDicts.put( name, item ); + item.setSelected( true ); + } + } else { + Assert.fail(); + } } return result; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 06d89d7ad..54964b368 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -123,7 +123,7 @@ public class GamesListDelegate extends ListDelegateBase } @Override - public View getView( Object dataObj ) + public View getView( Object dataObj, View convertView ) { View result = null; if ( dataObj instanceof GroupRec ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ListGroup.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ListGroup.java index 1f5cf6c08..cbb61e69c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ListGroup.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ListGroup.java @@ -87,11 +87,17 @@ public class ListGroup extends LinearLayout } } - public static ListGroup make( Context context, GroupStateListener lstnr, - int posn, String lang, boolean expanded ) + public static ListGroup make( Context context, View convertView, + GroupStateListener lstnr, int posn, + String lang, boolean expanded ) { - ListGroup result = (ListGroup) - LocUtils.inflate( context, R.layout.list_group ); + ListGroup result; + if ( null != convertView && convertView instanceof ListGroup ) { + result = (ListGroup)convertView; + } else { + result = (ListGroup) + LocUtils.inflate( context, R.layout.list_group ); + } result.m_posn = posn; result.m_expanded = expanded; result.m_langName = lang; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpListAdapter.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpListAdapter.java index ae904ce96..2280a17d3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpListAdapter.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWExpListAdapter.java @@ -51,7 +51,7 @@ abstract class XWExpListAdapter extends XWListAdapter { } abstract Object[] makeListData(); - abstract View getView( Object dataObj ); + abstract View getView( Object dataObj, View convertView ); @Override public int getCount() @@ -86,7 +86,7 @@ abstract class XWExpListAdapter extends XWListAdapter { DbgUtils.logf( "getView: missing opportunity to reuse view %H", convertView ); } - View result = getView( m_listObjs[position] ); + View result = getView( m_listObjs[position], convertView ); // DbgUtils.logf( "getView(position=%d) => %H (%s)", position, result, // result.getClass().getName() ); return result; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListItem.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListItem.java index 8fbe7f95c..13c088c4a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListItem.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListItem.java @@ -75,9 +75,10 @@ public class XWListItem extends LinearLayout protected void setExpandedListener( ExpandedListener lstnr ) { - Assert.assertNull( m_expListener ); // call me only once m_expListener = lstnr; - setOnClickListener( this ); + if ( null != lstnr ) { + setOnClickListener( this ); + } } protected void setExpanded( boolean expanded )