我正在使用RecyclerView从Firebase Storage中加载我的图片。然而,当我加载像A这样的图像并滚动到该图像视图被回收并用于显示图像B时,我仍然可以短暂地看到图像A,然后才会更改为图像B。
有没有办法避免这种情况发生?
以下是我的适配器代码:
有没有办法避免这种情况发生?
以下是我的适配器代码:
public class ComicRecyclerAdapter extends RecyclerView.Adapter<ComicRecyclerAdapter.ComicHolder> {
public ComicRecyclerAdapter(ArrayList<Comic> comicsInSection) {
this.mComicsInSection = comicsInSection;
}
@Override
public ComicHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//Bind the Comic object to the ComicHolder
View comicView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_grid_comic, parent, false);
return new ComicRecyclerAdapter.ComicHolder(comicView);
}
@Override
public void onBindViewHolder(final ComicHolder holder, int position) {
Comic currentComic = mComicsInSection.get(position);
storageRef.child(currentComic.getTitle() + "/"
+ currentComic.getCoverImage()).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//Load image using Picasso
Picasso.get()
.load(uri)
.fit()
.into(holder.coverImage, new Callback() {
@Override
public void onSuccess() {
//image loaded stop loading icon
holder.loadingComic.setVisibility(View.GONE);
}
@Override
public void onError(Exception e) {
}
});
}
});
}
@Override
public int getItemCount() {
return (null != mComicsInSection ? mComicsInSection.size() : 0);
}
public void addAll(ArrayList<Comic> comicsToAdd) {
mComicsInSection.addAll(comicsToAdd);
notifyDataSetChanged();
}
public void clear() {
mComicsInSection.clear();
notifyDataSetChanged();
}
static class ComicHolder extends RecyclerView.ViewHolder {
//Find all views needed
@BindView(R.id.comic_cover_image)
ImageView coverImage;
@BindView(R.id.loading_comic)
ProgressBar loadingComic;
public ComicHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
}