【发布时间】:2019-07-09 10:23:53
【问题描述】:
有什么方法可以将LiveData<List<X>> 类型的对象转换为LiveData<PagedList<X>> 类型的对象?
【问题讨论】:
有什么方法可以将LiveData<List<X>> 类型的对象转换为LiveData<PagedList<X>> 类型的对象?
【问题讨论】:
据我所知,您可以通过以下方式做到这一点:
class FirstType
class SecondType
val initType: LiveData<FirstType> = MutableLiveData<FirstType>()
val resultType : LiveData<SecondType> = Transformations.map(initType, ::convertTypes)
fun convertTypes(firstType: FirstType) : SecondType = SecondType()
更新:
把List<T>转换成PagedList<T>试试看:
How to convert a List<Object> to PagedList<Object> and vice-versa?
【讨论】:
FirstType 更改为SecondType。类型相同X。这是关于将LiveData<PagedList<X>> 中的LiveData<List<X>> 转换为PagedList<X>,参见List<X>。有什么办法可以做到吗?
snapshot() 将PagedList<Object> 转换为List<Object> ,反之亦然。有可能吗?
snapshot()的解释,从Now as for the other way around...开始不是你需要的吗?