我一直在ListView中異步加載圖像,因爲當它們加載時,它們中的一些閃爍(它們被另一個加載的圖像替換)以及一些他們顯示在錯誤的項目。Android異步加載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);
我應該怎麼做不同?
發表您的適配器代碼! – mmlooloo 2014-10-09 02:36:02