Skip to content

Instantly share code, notes, and snippets.

@laggedHero
Forked from target-trust/convertView.java
Last active August 29, 2015 14:09
Show Gist options
  • Save laggedHero/750e42cc217044b4f223 to your computer and use it in GitHub Desktop.
Save laggedHero/750e42cc217044b4f223 to your computer and use it in GitHub Desktop.
// Without a View Holder
@Override
publicView getView(int itempos, View convertView, ViewGroup parent) {
// Check if the convertview is null, if it is null it probably means that this
// is the first time the view has been displayed
if (convertView == null) {
convertView = View.inflate(context, R.layout.list_content_layout, null);
}
// If it is not null, you can just reuse it from the recycler
TextView txtcontent = (TextView) convertView.findViewById(R.id.textView1);
ImageView imgcontent = (ImageView) convertView.findViewById(R.id.imageView1);
Paintings paintingcontent = content[itempos];
txtcontent.setText(paintingcontent.imagetitle);
imgcontent.setImageResource(paintingcontent.drawableresid);
// return the view for a single item in the listview
return convertView;
}
// With a View Holder
@Override
publicView getView(int itempos, View convertView, ViewGroup parent) {
ViewHolder holder;
// Check if the convertview is null, if it is null it probably means that this
// is the first time the view has been displayed
if (convertView == null) {
convertView = View.inflate(context, R.layout.list_content_layout, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.textView1);
holder.image = (ImageView) convertView.findViewById(R.id.imageView1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Paintings paintingcontent = content[itempos];
holder.text.setText(paintingcontent.imagetitle);
holder.image.setImageResource(paintingcontent.drawableresid);
// return the view for a single item in the listview
return convertView;
}
// The View Holder
static class ViewHolder {
TextView text;
ImageView image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment