Android 数据绑定:可观察列表到 RecyclerView 的适配器 [英] Android Data Binding : Observable List to RecyclerView's Adapter
问题描述
是他们的一种方法,通过使用来自新数据绑定库和 MVVM 模式的 ObservableList
类,以避免使用 "notifyItem(s)..."
Adapter
类中的方法?
Is their a way, by using the ObservableList
class from the new Data Binding library and the MVVM pattern, to avoid using "notifyItem(s)..."
methods from the Adapter
class?
或者如果不是,将 ObservableList
绑定到 RecyclerView
的最简单方法是什么?
Or if not what could be the simpliest way to bind an ObservableList
to a RecyclerView
?
感谢提供任何线索!
推荐答案
看看以下 RecyclerView
的适配器的实现:
Have a look at following implementation of the RecyclerView
's adapter:
如果OnListChangedCallback
被调用,它会自动通知回收者视图.
It automatically notifies the recycler view if the OnListChangedCallback
is called.
还可以查看存储库的其余部分.它展示了如何使用 xml 将您的 ObervableList
绑定到适配器.这样你就可以拥有这样的东西:
Also have a look at the rest of the repository. It shows how to bind your ObervableList
to the adapter using xml. So that you can have something like this:
app:items="@{usersViewModel.users}"
这篇关于Android 数据绑定:可观察列表到 RecyclerView 的适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!