Android数据绑定:可观察到的RecyclerView适配器列表 [英] Android Data Binding : Observable List to RecyclerView's Adapter
问题描述
通过使用新的数据绑定库中的ObservableList
类和MVVM模式,是否可以避免使用Adapter
类中的"notifyItem(s)..."
方法?
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屋!