mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
Recycle convertView for dicts list elements. Next: games list.
This commit is contained in:
parent
1864675196
commit
f3f5bf10a5
5 changed files with 63 additions and 51 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Reference in a new issue