Skip to content

Instantly share code, notes, and snippets.

Created May 26, 2013 14:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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);
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);
} 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