I have created a Staggered List using RecyclerView v28.0.0 in combination with Glide Image Library v4.9.0.
Please do not mark this question as duplicate because I referred below items before posting this question:
- Glide recyclerview loading duplicate image RecyclerView duplicating items some time http://bumptech.github.io/glide/doc/getting-started.html#listview-and-recyclerview
I create an Adapter using DataBoundListAdapter that includes diff callback as well.
To make sure each recycler view item is picking up a unique ID, I'd use hashmap as:
override fun bind(binding: ItemStockBinding, item: InventoryProductWithSKU, position: Int) {
mContext?.let {
Glide.with(it)
.load(mIdImageMap[item.inventoryProductEntity.id])
.apply(RequestOptions().placeholder(R.drawable.place_holder)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.error(R.drawable.place_holder))
.placeholder(R.drawable.place_holder)
.into(binding.layoutProductImage)
} }
And, To handle the case if Image not present, I'd:
Glide.with(mContext!!).clear(binding.layoutProductImage)
binding.layoutProductImage.setImageDrawable(null)
This issue is recurring at most of the places in our app. Please suggest any workaround.
Thanks.