Hello,
To display & load images in my ListView I've created a custom ArrayAdapter, however it is really slow. Every time I scroll through the list it loads the images again.
Is there a caching mechanism which will cache my Views so I don't need to refill them every time? I know about the ViewHolder method, however this still is slow or am I just using it wrong?
My code:
public class ImageArrayAdapter extends ArrayAdapter<HashMap<String, String>> {
private int resourceId = 0;
private LayoutInflater inflater;
public ImageArrayAdapter(Context context, int resource,
List<HashMap<String, String>> objects) {
super(context, 0, objects);
this.resourceId = resource;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public static class ViewHolder {
public TextView title;
public TextView text;
public WebImageView image;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if (view == null) {
view = inflater.inflate(resourceId, parent, false);
holder = new ViewHolder();
holder.text = (TextView) view.findViewById(R.id.item_text);
holder.image = (WebImageView) view.findViewById(R.id.item_image);
holder.title = (TextView) view.findViewById(R.id.item_title);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
HashMap<String, String> item = (HashMap<String, String>) getItem(position);
holder.text.setText(item.get("text"));
holder.title.setText(item.get("title"));
holder.image.setImageUrl(item.get("image"));
holder.image.loadImage();
return view;
}
}