I have been struggling with asynchronously loading images in ListView, because while they're loading, some of them are blinking (they're are replaced by another loaded image) and some of them are showed in wrong items.
Class for downloading images:
class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls)
{
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try
{
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
}
catch (Exception e) {}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
Calls for each item, when I am assigning data to ListView:
ImageView image = (ImageView)view.findViewById(R.id.imageView);
TextView title = (TextView)view.findViewById(R.id.txtTitle);
new DownloadImageTask(image).execute(data.image);
title.setText(data.title);
What should I do differently?