Skip to content

Instantly share code, notes, and snippets.

@ubiratansoares
Created May 26, 2013 14:37
Show Gist options
  • Save ubiratansoares/5652976 to your computer and use it in GitHub Desktop.
Save ubiratansoares/5652976 to your computer and use it in GitHub Desktop.
A simple idea for a less bloated (Array)Adapter implementation, using ViewHolder pattern.
public abstract class FasterArrayAdapter<T> extends ArrayAdapter<T> {
protected abstract Object getHolder();
protected abstract int layoutResourceForItem();
protected abstract void setupHolder(View convertView, Object tag);
protected abstract void fillHolder(Object tag, int position);
protected LayoutInflater mInflater;
public FasterArrayAdapter(Context context, List<T> objects) {
super(context, 0, objects);
mInflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Object viewHolder = null;
if (convertView == null) {
viewHolder = getHolder();
convertView = mInflater.inflate(layoutResourceForItem(), parent, false);
setupHolder(convertView, viewHolder);
convertView.setTag(viewHolder);
} else {
viewHolder = convertView.getTag();
}
fillHolder(viewHolder, position);
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment