Created
March 25, 2015 09:52
-
-
Save ok3141/26bef66f10728bdf3e2d to your computer and use it in GitHub Desktop.
Optimize ListView items which update frequently
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 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