我在 GridView 中使用 Droidfu 的小部件 WebImageView 来创建画廊。图像正在与 WebImageView 异步下载并缓存。
问题是当网格滚动到它时 id 并不总是显示图像(它显示默认错误 img )。就像 getView 正在破坏它并且每次都无法正确回收它。
这是我的 GridAdapter
公共类 GalleryAdapter 扩展 BaseAdapter {
private Context mContext;
public GalleryAdapter(Context c) {
// TODO Auto-generated constructor stub
mContext = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return theList.getItemCount();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return theList.getItem(arg0);
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final GalleryItem galeryItem = theList.getItem(position);
if (convertView == null) {
convertView = (View) getLayoutInflater().inflate(R.layout.gallery_item, parent, false);
}
WebImageView imageView = (WebImageView) convertView.findViewById(R.id.webimage);
if (!galeryItem.getMain_image().trim().equalsIgnoreCase("")) {
imageView.setScaleType(ScaleType.CENTER_CROP);
imageView.setAdjustBounds(true);
imageView.reset();
imageView.setImageUrl(galeryItem.getMain_image().trim());
imageView.setNoImageDrawable(R.drawable.heading_img_bg);
imageView.loadImage();
}
TextView heading = (TextView) convertView.findViewById(R.id.gallery_heading);
heading.setText(galeryItem.getHeading());
TextView img_num = (TextView) convertView.findViewById(R.id.gallery_img_num);
img_num.setText(Integer.toString(galeryItem.getImage_num()));
return convertView;
}
}