我在onBindViewHolder中使用Picasso但是当向上或向下滚动它从互联网上重新加载相同的图像网址时,这会使列表变得如此糟糕和缓慢
所以我想在它第一次加载时保存图像的滚动状态而不再加载它
我怎么能这样做?
onBindViewHolder方法:
@Override
public void onBindViewHolder(MyCustomAdapter.CustomViewHolder holder, int position) {
Dishes di = dish.get(position);
//Download image using picasso library
Picasso.with(mContext).load(di.getDishImageUrl())
.error(R.drawable.ic_error)
.placeholder(R.drawable.fav_btn)
.into(holder.imageView);
//Setting text view title
holder.textView.setText(Html.fromHtml(di.getDishName()));
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
CustomViewHolder holder = (CustomViewHolder) view.getTag();
int position = holder.getPosition();
Dishes di = dish.get(position);
Toast.makeText(mContext, di.getDishName(), Toast.LENGTH_SHORT).show();
}
};
//Handle click event on both title and image click
holder.textView.setOnClickListener(clickListener);
holder.imageView.setOnClickListener(clickListener);
holder.textView.setTag(dish.get(position));
holder.imageView.setTag(dish.get(position));
}