liangjingkanji / BRV

[使用文档] Android 快速构建 RecyclerView, 比 BRVAH 更简单强大
http://liangjingkanji.github.io/BRV/
MIT License
2.59k stars 327 forks source link

多类型问题求助 #339

Closed senselesscn closed 1 year ago

senselesscn commented 1 year ago

问题描述

addType<Uri>(R.layout.xxx)会报错,其实已经知道是类型不匹配引起的了,我添加的类型是Uri,系统给我返回的是HierarchicalUri。这个问题可以用一个类声明一个Uri属性来解决,但除此之外框架能否解决这个问题

期望行为

我希望点击某个按钮从系统相册获取一张照片,然后得到Uri在recyclerview中显示这张照片。

如何复现

    private val imageUris = mutableListOf<Any>()
    imageUris.add(R.mipmap.fb_add)
    val adapter = binding.rvImages.setup {
        addType<Uri>(R.layout.item_feedback_image)
        addType<Int>(R.layout.item_feedback_image)
    }
    adapter.models = imageUris
    launcher = registerForActivityResult(GetSingleContent()) {
        if (it != null) {
            imageUris.add(0, it)
            if (imageUris.size == 5) {
                imageUris.removeLast()
            }
            adapter.notifyDataSetChanged()
        }
    }

截图

image

版本

liangjingkanji commented 1 year ago

HierarchicalUri不能作为类型添加吗?

liangjingkanji commented 1 year ago

首先我想问的是这是一个问题吗?

senselesscn commented 1 year ago

HierarchicalUri不能作为类型被添加

liangjingkanji commented 1 year ago

私有类?实现了Uri? 那可以使用添加接口类型方法,具体看文档介绍,我暂时没有电脑在身边

senselesscn commented 1 year ago

Uri是个抽象类,HierarchicalUri是Uri的私有类,我注意到现在框架对接口类型做了兼容,还没有抽象类型的兼容。这可能是我用法有问题,已经解决了