Android数据绑定:可观察到的RecyclerView适配器列表 [英] Android Data Binding : Observable List to RecyclerView's Adapter

查看:482
本文介绍了Android数据绑定:可观察到的RecyclerView适配器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用新的数据绑定库中的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆