Skip to content

Instantly share code, notes, and snippets.

@scottagarman
Created August 21, 2014 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottagarman/562bab31126b55d84197 to your computer and use it in GitHub Desktop.
Save scottagarman/562bab31126b55d84197 to your computer and use it in GitHub Desktop.
public View getView(int position, View convertView, ViewGroup parent) {
ListViewHolder holder = ListViewHolder.get(convertView, parent);
holder.name.setText("some text");
return holder.root; // or convertView
}
public class ListViewHolder {
public static ListViewHolder get(View convertView, ViewGroup parent) {
if(convertView == null || convertView.getTag() == null || !(convertView.getTag() instanceof ListViewHolder)) {
return new ListViewHolder(parent);
} else {
return (ListViewHolder)convertView.getTag();
}
}
public final View root;
public final TextView name;
private ListViewHolder(ViewGroup parent) {
root = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_, parent, false);
root.setTag(this);
name = (TextView)root.findViewById(R.id.item_text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment