【发布时间】:2019-02-02 11:15:27
【问题描述】:
我想知道为什么即使我设置了适配器,当我滚动 gridview 时,第一个位置的视图也会被重复调用。这导致我的 gridview 在反复重新加载图像时无法平滑滚动。
似乎Picasso.with(context).load(file).into(viewImage);导致重复调用,因为如果我删除这一行,gridview可以平滑滚动。
有什么改进的建议吗?谢谢。
gridview数组适配器的实现
class HomeBrandCVC extends ArrayAdapter<Brand> {
private Context context;
private ArrayList<Brand> brandArrayList;
private Map<Integer, File> fileMap = new HashMap<>();
public HomeBrandCVC(Context c, ArrayList<Brand> brandArrayList) {
super(c, R.layout.homecvc, brandArrayList);
this.context = c;
this.brandArrayList = brandArrayList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.homecvc, parent, false);
TextView nameLabel = (TextView) rowView.findViewById(R.id.homecvc_nameLabel);
nameLabel.setVisibility(View.INVISIBLE);
final Brand brand = brandArrayList.get(position);
nameLabel.setText(brand.name);
ImageView viewImage = (ImageView) rowView.findViewById(R.id.homecvc_viewImage);
Log.d("hellllo", String.valueOf(position));
if (fileMap.containsKey(position)) {
viewImage.setImageBitmap(BitmapFactory.decodeFile(fileMap.get(position).getAbsolutePath()));
} else {
viewImage.setImageResource(R.drawable.loadingimage);
new MyLeanCloudApp.GetImageFromDiskOrUrl(brand.imageFile, new MyLeanCloudApp.ImageHandlerGetImagesResponse() {
@Override
public void processFinish(File file) {
if (context != null) {
if (file != null) {
Picasso.with(context).load(file).into(viewImage);
fileMap.put(position, file);
}
}
}
}).execute();
}
return rowView;
}
}
【问题讨论】:
标签: gridview android-arrayadapter