summaryrefslogtreecommitdiff
path: root/Source/Android/src
diff options
context:
space:
mode:
authorEder Bastos <bastos.eder@gmail.com>2014-06-24 22:27:34 -0400
committerEder Bastos <bastos.eder@gmail.com>2014-06-24 23:03:38 -0400
commit53e4f3d73cb1e4ac906ad13c245bc6c1f45f0640 (patch)
tree0ea9ae56a0faee10fccac5536b6cbcb6b56f48b5 /Source/Android/src
parenteb3de73ab9c47a77ac86e64c207a78e3ce8fb466 (diff)
Implement ViewHolder pattern on the GameListAdapter.
Diffstat (limited to 'Source/Android/src')
-rw-r--r--Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java57
1 files changed, 37 insertions, 20 deletions
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java
index 8ce1afd216..30796593ca 100644
--- a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java
+++ b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java
@@ -41,38 +41,55 @@ public final class GameListAdapter extends ArrayAdapter<GameListItem>
}
@Override
- public View getView(int position, View convertView, ViewGroup parent)
+ public View getView(int position, View gameView, ViewGroup parent)
{
- if (convertView == null)
+ ViewHolder holder;
+
+ // If getView() was called without passing in a recycled view,
+ if (gameView == null)
+ {
+ // Inflate a new view using the appropriate XML layout.
+ LayoutInflater inflater = LayoutInflater.from(context);
+ gameView = inflater.inflate(id, parent, false);
+
+ // Instantiate a holder to contain references to the game's views.
+ holder = new ViewHolder();
+ holder.title = (TextView) gameView.findViewById(R.id.GameListItemTitle);
+ holder.subtitle = (TextView) gameView.findViewById(R.id.GameListItemSubTitle);
+ holder.icon = (ImageView) gameView.findViewById(R.id.GameListItemIcon);
+
+ // Attach this list of references to the view.
+ gameView.setTag(holder);
+ }
+ // If we do have a recycled view, we can use the references it already contains.
+ else
{
- LayoutInflater vi = LayoutInflater.from(context);
- convertView = vi.inflate(id, parent, false);
+ holder = (ViewHolder) gameView.getTag();
}
+ // Get a reference to the game represented by this row.
final GameListItem item = getItem(position);
+
+ // Whether this row's view is newly created or not, set the children to contain the game's data.
if (item != null)
{
- TextView title = (TextView) convertView.findViewById(R.id.GameListItemTitle);
- TextView subtitle = (TextView) convertView.findViewById(R.id.GameListItemSubTitle);
- ImageView icon = (ImageView) convertView.findViewById(R.id.GameListItemIcon);
-
- if (title != null)
- title.setText(item.getName());
-
- if (subtitle != null)
- subtitle.setText(item.getData());
-
- if (icon != null)
- {
- icon.setImageBitmap(item.getImage());
- }
+ holder.title.setText(item.getName());
+ holder.subtitle.setText(item.getData());
+ holder.icon.setImageBitmap(item.getImage());
}
// Make every other game in the list grey
if (position % 2 == 1)
- convertView.setBackgroundColor(0xFFE3E3E3);
+ gameView.setBackgroundColor(0xFFE3E3E3);
- return convertView;
+ return gameView;
+ }
+
+ private final class ViewHolder
+ {
+ public TextView title;
+ public TextView subtitle;
+ public ImageView icon;
}
}