Created
May 26, 2013 14:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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