【问题标题】:How to sort MutableLiveData<List<Book>>如何排序 MutableLiveData<List<Book>>
【发布时间】:2020-04-16 03:50:13
【问题描述】:

我在 ViewModel 中有 MutableLiveData>。我们如何根据书名、id等对其进行排序。

【问题讨论】:

  • 到目前为止您尝试过什么,您还看过哪些地方?

标签: sorting kotlin viewmodel mutablelivedata


【解决方案1】:

您可以使用map function 来转换您的LiveData

val unsortedBooks: LiveData<Book> = //...
val sortedBooks: LiveData<Book> = Transformations
    .map(unsortedBooks, Function { books ->
        //sort your `books` here and return the sorted list
    })

【讨论】:

    猜你喜欢
    • 2021-03-20
    • 2022-08-05
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 2010-09-28
    相关资源
    最近更新 更多