我一直在努力,在ListView中异步加载图像,因为他们正在加载时,他们中的一些闪烁(他们被另一个加载图像取代),其中一些在错误的项目显示。
类下载图片:
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);
}
}
要求每一个项目,当我到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);
我应该怎么做不同?