Skip to content

Instantly share code, notes, and snippets.

@ok3141
Created March 25, 2015 09:52
Show Gist options
  • Save ok3141/26bef66f10728bdf3e2d to your computer and use it in GitHub Desktop.
Save ok3141/26bef66f10728bdf3e2d to your computer and use it in GitHub Desktop.
Optimize ListView items which update frequently
public View getView(int position, View convertView, ViewGroup parent) {
// check convertView, inflate new layout, obtain ViewHolder, get data item, etc.
ViewHolder holder = ... ;
Data item = getItem(position);
if (holder.item != item) {
holder.item = item;
holder.titleView.setText(item.title);
holder.openTimeView.setText(item.openTime);
}
holder.ratingView.setText(item.rating);
holder.discountView.setText(item.discount);
}
public class Data {
// these two fields will never change
String title;
String openTime;
// these fields will change frequently
String rating;
String discount;
}
public class ViewHolder {
TextView titleView;
TextView openTimeView;
TextView ratingView;
TextView discountView;
Data item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment