简体   繁体   English

滚动时,recyclerview中的收藏夹和收藏夹图像处于初始状态

[英]favourite and unfavourite image in recyclerview gets in initial state when scrolled

I have a recycler adapter in which there are 3 image buttons, one of them is for favorite and unfavorite. 我有一个回收站适配器,其中有3个图像按钮,其中一个按钮用于收藏夹和收藏夹。 when the recyclerviews loads its loads proper also when I click on favorite it stores in my favorite list. 当recyclerviews正确加载其负载时,当我单击收藏夹时,它也会存储在我的收藏夹列表中。 But the problem is that when I scrolled it the states of image button changes to load time images. 但是问题是,当我滚动它时,图像按钮的状态会更改为加载时间图像。

确保在onBindViewHolder上设置收藏夹/收藏夹。

RecyclerView efficiently recycles views while you scroll. RecyclerView可以在滚动时有效地回收视图。

when you maintain this kind of scenario, where image view can have Fav or UnFav images. 当您维护这种情况时,图像视图中可以包含Fav或UnFav图像。 you need to maintain both in onBindVIewHolder() method such as 您需要同时维护onBindVIewHolder()方法,例如

if (isFav) {
viewHolder.yourImage.setBackgroundDrawable(FavImage);
} else {
viewHolder.yourImage.setBackgroundDrawable(UnFavImage);
}

尝试在每种情况下在#onBindViewHolder上设置图像(不要假设您知道当前状态)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM