【发布时间】:2015-02-01 19:34:31
【问题描述】:
我想知道是否有办法让 BindView 每个项目只工作一次?
我们滚动离开屏幕的项目会被破坏吗?当他们回来时,我们必须再次运行 bindview 吗?
原因是我让我的适配器下载图像并将其设置在项目上。
当我滚动时,图像会再次下载,即使我没有退出应用程序。
每次一个项目“返回”显示时都会调用 bindview,所以即使我已经下载了它,它也会再次执行 asyntask(在适配器中调用 asyntask)
我什至尝试在每次下载后将 BLOB 保存在我的数据库中,以了解何时调用 asyntast 以及何时从数组中制作位图
if(photoBArray != null){
Bitmap bitmap = BitmapFactory.decodeByteArray(photoBArray, 0, photoBArray.length);
holder.icon.setImageBitmap(bitmap);
}else{
holder.icon.setImageResource(R.drawable.loader);
String urlString = "https://maps.googleapis.com/maps/api/place/photo?maxwidth=100&photoreference="
+ c.getString(c.getColumnIndex(PlacesDBHelper.PHOTO_REFERENCE_COL))+"&key=API_KEY";
Log.e("Photo REFERENCE", c.getString(c.getColumnIndex(PlacesDBHelper.PHOTO_REFERENCE_COL)));
try {
URL url = new URL(urlString); // create new URL object from url string
new ImageDownloader(holder.icon, this).execute(url);
}catch (Exception e){
Log.e("Error in url", e.getMessage());
}
}
我也在使用 chrisbanes pulltorefresh listview,我不确定这是否是问题的原因
底线问题:当一个项目回到屏幕而不是重新创建时,如何让一个项目看起来稳定和准备好? (因为即使我不下载图像而只设置位图,setimagebitmap 的操作也可能在慢速手机上可见)
提前致谢!
【问题讨论】:
标签: android bitmap android-asynctask simplecursoradapter pull-to-refresh