Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge "Enhance performance by using ViewHolder"

  • Loading branch information...
commit 1e320f8814457b165a1dc25d9b21d03546808c9d 2 parents 3d0efa0 + da3bbf3
Tom Taylor authored Gerrit Code Review committed
Showing with 31 additions and 5 deletions.
  1. +31 −5 src/com/android/mms/ui/IconListAdapter.java
View
36 src/com/android/mms/ui/IconListAdapter.java
@@ -35,7 +35,33 @@
public class IconListAdapter extends ArrayAdapter<IconListAdapter.IconListItem> {
protected LayoutInflater mInflater;
private static final int mResource = R.layout.icon_list_item;
+ private ViewHolder mViewHolder;
+ static class ViewHolder {
+ private View mView;
+ private TextView mTextView;
+ private ImageView mImageView;
+
+ public ViewHolder(View view) {
+ mView = view;
+ }
+
+ public TextView getTextView() {
+ if (mTextView == null) {
+ mTextView = (TextView) mView.findViewById(R.id.text1);
+ }
+
+ return mTextView;
+ }
+
+ public ImageView getImageView() {
+ if (mImageView == null) {
+ mImageView = (ImageView) mView.findViewById(R.id.icon);
+ }
+
+ return mImageView;
+ }
+ }
public IconListAdapter(Context context,
List<IconListItem> items) {
super(context, mResource, items);
@@ -44,22 +70,22 @@ public IconListAdapter(Context context,
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- TextView text;
- ImageView image;
-
View view;
if (convertView == null) {
view = mInflater.inflate(mResource, parent, false);
+ mViewHolder = new ViewHolder(view);
+ view.setTag(mViewHolder);
} else {
view = convertView;
+ mViewHolder = (ViewHolder) view.getTag();
}
// Set text field
- text = (TextView) view.findViewById(R.id.text1);
+ TextView text = mViewHolder.getTextView();
text.setText(getItem(position).getTitle());
// Set resource icon
- image = (ImageView) view.findViewById(R.id.icon);
+ ImageView image = mViewHolder.getImageView();
image.setImageResource(getItem(position).getResource());
return view;
Please sign in to comment.
Something went wrong with that request. Please try again.