I have a ListView with an ArrayAdapter holding rows with a Image and a String. This worked fine until I decided that the loading of the images was to slow so I could not load the images before showing the list. So I started to load the images in a separate thread using an AsyncTask
.
I was very happy with the result until I started to scroll the list. Wrong images was loaded and it doesn't look like it is a question of the image getting a while later. If I attempt to sort the list the problem goes really bad and none of the images is on the right row.
Any ideas of what I'm doing wrong?
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ImageView imageView;
TextView textView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.drink_list_row, null);
}
Drink drink = allItems.get(position);
if (drink != null && v != null) {
imageView = (ImageView) v.findViewById(R.id.picture);
textView = (TextView) v.findViewById(R.id.drinkName);
imageView.setVisibility(View.GONE);
loadImageBitmap(drink, imageView);
textView.setText(drink.getName());
if (subItems != null && subItems.contains(drink)) {
textView.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
} else {
textView.setVisibility(View.GONE);
imageView.setVisibility(View.GONE);
}
}
return v;
}