recycle views for games list elements too

This commit is contained in:
Eric House 2014-07-10 06:24:35 -07:00
parent f3f5bf10a5
commit e674ae4a3c
4 changed files with 23 additions and 14 deletions

View file

@ -48,14 +48,20 @@ public class GameListGroup extends ExpiringLinearLayout
private ImageButton m_expandButton; private ImageButton m_expandButton;
public static GameListGroup makeForPosition( Context context, public static GameListGroup makeForPosition( Context context,
View convertView,
long groupID, long groupID,
int nGames, int nGames,
boolean expanded, boolean expanded,
SelectableItem cb, SelectableItem cb,
GroupStateListener gcb ) GroupStateListener gcb )
{ {
GameListGroup result = (GameListGroup) GameListGroup result;
LocUtils.inflate( context, R.layout.game_list_group ); if ( null != convertView && convertView instanceof GameListGroup ) {
result = (GameListGroup)convertView;
} else {
result = (GameListGroup)
LocUtils.inflate( context, R.layout.game_list_group );
}
result.m_cb = cb; result.m_cb = cb;
result.m_gcb = gcb; result.m_gcb = gcb;
result.m_groupID = groupID; result.m_groupID = groupID;

View file

@ -364,12 +364,17 @@ public class GameListItem extends LinearLayout
} }
} // class LoadItemTask } // class LoadItemTask
public static GameListItem makeForRow( Context context, long rowid, public static GameListItem makeForRow( Context context, View convertView,
Handler handler, int fieldID, long rowid, Handler handler,
SelectableItem cb ) int fieldID, SelectableItem cb )
{ {
GameListItem result = GameListItem result;
(GameListItem)LocUtils.inflate( context, R.layout.game_list_item ); if ( null != convertView && convertView instanceof GameListItem ) {
result = (GameListItem)convertView;
} else {
result = (GameListItem)LocUtils.inflate( context,
R.layout.game_list_item );
}
result.init( handler, rowid, fieldID, cb ); result.init( handler, rowid, fieldID, cb );
return result; return result;
} }

View file

@ -131,8 +131,9 @@ public class GamesListDelegate extends ListDelegateBase
GameGroupInfo ggi = DBUtils.getGroups( m_activity ) GameGroupInfo ggi = DBUtils.getGroups( m_activity )
.get( rec.m_groupID ); .get( rec.m_groupID );
GameListGroup group = GameListGroup group =
GameListGroup.makeForPosition( m_activity, rec.m_groupID, GameListGroup.makeForPosition( m_activity, convertView,
ggi.m_count, ggi.m_expanded, rec.m_groupID, ggi.m_count,
ggi.m_expanded,
GamesListDelegate.this, GamesListDelegate.this,
GamesListDelegate.this ); GamesListDelegate.this );
if ( !ggi.m_expanded ) { if ( !ggi.m_expanded ) {
@ -148,7 +149,8 @@ public class GamesListDelegate extends ListDelegateBase
} else if ( dataObj instanceof GameRec ) { } else if ( dataObj instanceof GameRec ) {
GameRec rec = (GameRec)dataObj; GameRec rec = (GameRec)dataObj;
GameListItem item = GameListItem item =
GameListItem.makeForRow( m_activity, rec.m_rowID, m_handler, GameListItem.makeForRow( m_activity, convertView,
rec.m_rowID, m_handler,
m_fieldID, GamesListDelegate.this ); m_fieldID, GamesListDelegate.this );
item.setSelected( m_selGames.contains( rec.m_rowID ) ); item.setSelected( m_selGames.contains( rec.m_rowID ) );
result = item; result = item;

View file

@ -82,10 +82,6 @@ abstract class XWExpListAdapter extends XWListAdapter {
@Override @Override
public View getView( int position, View convertView, ViewGroup parent ) public View getView( int position, View convertView, ViewGroup parent )
{ {
if ( null != convertView ) {
DbgUtils.logf( "getView: missing opportunity to reuse view %H",
convertView );
}
View result = getView( m_listObjs[position], convertView ); View result = getView( m_listObjs[position], convertView );
// DbgUtils.logf( "getView(position=%d) => %H (%s)", position, result, // DbgUtils.logf( "getView(position=%d) => %H (%s)", position, result,
// result.getClass().getName() ); // result.getClass().getName() );