我有一个列表视图的图像。异步任务完成后更新列表视图Android
如果本地缓存中不存在图像,则占位符图像将保留在图像的位置。
然后运行一个异步任务从服务器下载图像。
异步任务完成后,我将imageView位图设置为下载的图像。 然后我打电话notifyDataSetChanged()
问题是我需要向下滚动并向上滚动以显示每个单元格以显示已下载的新图像。它不会自动更新单元格。
所以我必须:
public class ImageLoadTask extends AsyncTask<Void, Void, Bitmap> {
private ImageView imageView;
public ImageLoadTask(ImageView imageView) {
this.imageView = imageView;
}
@Override
protected Bitmap doInBackground(Void... params) {
// download image from server and return
}
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
imageView.setImageBitmap(result)
notifyDataSetChanged()
}
}
在我getView()方法,我有:
if(image exists in cache){
myImageView.setBitmap(image in Cache);
}else{
new ImageLoadTask(myImageView).execute()
}
这样被保存在缓存做工精细任何图像。
任何必须首先下载的图像都不会正确更新,除非您向下滚动并再次备份。
什么问题?
我建议你使用凌空或毕加索图书馆来加载图像。 –
你需要做以下 //清除现有项目 'listAdapter.clear();' //添加新项目 'listAdapter.addAll(updatedvalues);' //通知,该数据已经改变 ' listAdapter.notifyDataSetChanged();' –