如何将 LiveData<List<X>> 转换成 LiveData<PagedList<X>>?
How to transform a LiveData<List<X>> in 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?
有什么方法可以将 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?