Use a ViewHolder static class to avoid most findViewById calls
This commit is contained in:
parent
bd2e379073
commit
463561d971
@ -79,37 +79,55 @@ abstract public class AppListAdapter extends BaseAdapter {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ViewHolder {
|
||||||
|
TextView name;
|
||||||
|
TextView summary;
|
||||||
|
TextView status;
|
||||||
|
TextView license;
|
||||||
|
ImageView icon;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
|
||||||
boolean compact = Preferences.get().hasCompactLayout();
|
boolean compact = Preferences.get().hasCompactLayout();
|
||||||
DB.App app = items.get(position);
|
DB.App app = items.get(position);
|
||||||
|
ViewHolder holder;
|
||||||
|
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = mInflater.inflate(R.layout.applistitem, null);
|
convertView = mInflater.inflate(R.layout.applistitem, null);
|
||||||
|
|
||||||
|
holder = new ViewHolder();
|
||||||
|
holder.name = (TextView) convertView.findViewById(R.id.name);
|
||||||
|
holder.summary = (TextView) convertView.findViewById(R.id.summary);
|
||||||
|
holder.status = (TextView) convertView.findViewById(R.id.status);
|
||||||
|
holder.license = (TextView) convertView.findViewById(R.id.license);
|
||||||
|
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
|
||||||
|
|
||||||
|
convertView.setTag(holder);
|
||||||
|
} else {
|
||||||
|
holder = (ViewHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView name = (TextView) convertView.findViewById(R.id.name);
|
holder.name.setText(app.name);
|
||||||
TextView summary = (TextView) convertView.findViewById(R.id.summary);
|
holder.summary.setText(app.summary);
|
||||||
TextView status = (TextView) convertView.findViewById(R.id.status);
|
|
||||||
TextView license = (TextView) convertView.findViewById(R.id.license);
|
|
||||||
ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
|
|
||||||
|
|
||||||
name.setText(app.name);
|
layoutIcon(holder.icon, compact);
|
||||||
summary.setText(app.summary);
|
ImageLoader.getInstance().displayImage(app.iconUrl, holder.icon,
|
||||||
|
|
||||||
int visibleOnCompact = compact ? View.VISIBLE : View.GONE;
|
|
||||||
int notVisibleOnCompact = compact ? View.GONE : View.VISIBLE;
|
|
||||||
|
|
||||||
layoutIcon(icon, compact);
|
|
||||||
ImageLoader.getInstance().displayImage(app.iconUrl, icon,
|
|
||||||
displayImageOptions);
|
displayImageOptions);
|
||||||
|
|
||||||
status.setText(getVersionInfo(app));
|
holder.status.setText(getVersionInfo(app));
|
||||||
license.setText(app.license);
|
holder.license.setText(app.license);
|
||||||
|
|
||||||
// Disable it all if it isn't compatible...
|
// Disable it all if it isn't compatible...
|
||||||
View[] views = { convertView, status, summary, license, name };
|
View[] views = {
|
||||||
|
convertView,
|
||||||
|
holder.status,
|
||||||
|
holder.summary,
|
||||||
|
holder.license,
|
||||||
|
holder.name
|
||||||
|
};
|
||||||
|
|
||||||
for (View view : views) {
|
for (View view : views) {
|
||||||
view.setEnabled(app.compatible && !app.filtered);
|
view.setEnabled(app.compatible && !app.filtered);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user