首页 > 解决方案 > 具有重复图像的 RecyclerView 项目

问题描述

我使用 RecyclerView v28.0.0 和 Glide Image Library v4.9.0 创建了一个交错列表。

请不要将此问题标记为重复,因为我在发布此问题之前参考了以下项目:

我使用包含差异回调的 DataBoundListAdapter 创建了一个适配器。

为了确保每个回收者视图项目都获取一个唯一的 ID,我将使用 hashmap 作为:

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)
        } }

而且,如果 Image 不存在,为了处理这种情况,我会:

 Glide.with(mContext!!).clear(binding.layoutProductImage)
 binding.layoutProductImage.setImageDrawable(null)

这个问题在我们应用程序的大部分地方都反复出现。请提出任何解决方法。

谢谢。

标签: androidkotlinandroid-recyclerviewandroid-support-libraryandroid-glide

解决方案


推荐阅读