Closed senselesscn closed 1 year ago
addType<Uri>(R.layout.xxx)会报错,其实已经知道是类型不匹配引起的了,我添加的类型是Uri,系统给我返回的是HierarchicalUri。这个问题可以用一个类声明一个Uri属性来解决,但除此之外框架能否解决这个问题
addType<Uri>(R.layout.xxx)
我希望点击某个按钮从系统相册获取一张照片,然后得到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() } }
HierarchicalUri不能作为类型添加吗?
首先我想问的是这是一个问题吗?
HierarchicalUri不能作为类型被添加
私有类?实现了Uri? 那可以使用添加接口类型方法,具体看文档介绍,我暂时没有电脑在身边
Uri是个抽象类,HierarchicalUri是Uri的私有类,我注意到现在框架对接口类型做了兼容,还没有抽象类型的兼容。这可能是我用法有问题,已经解决了
问题描述
addType<Uri>(R.layout.xxx)
会报错,其实已经知道是类型不匹配引起的了,我添加的类型是Uri,系统给我返回的是HierarchicalUri。这个问题可以用一个类声明一个Uri属性来解决,但除此之外框架能否解决这个问题期望行为
我希望点击某个按钮从系统相册获取一张照片,然后得到Uri在recyclerview中显示这张照片。
如何复现
截图
版本