在两个回收者视图与两个活动之间同步数据的最佳模式是什么? [英] What is the best pattern to sync data between two recycler view with two activities?
问题描述
例如。
活动A 具有 recyclelerview ,其中每行具有唯一ID的按钮。 活动B 还具有相同的回收器视图,但使用一些过滤器机制,因此不会显示所有行,我的问题是如何处理像按钮状态为活动A 和活动B ,以便如果我点击活动B,如按钮活动A类似按钮将自动检查,反之亦然。
您应该为回收者视图使用通用数据源。
- 从API获取数据
- 将数据保存在本地数据库中
- 将数据提供给您的活动A回收商视图
- 将相同的数据提供给您的活动B回收商视图
- 您对数据所做的所有更改应为在本地数据库中,所以
视图都可以自动更新。
I have two activities where they have almost same data, I am using same Adapter, But the problem is how to sync data.
E.g. Activity A has recyclerview where it has like buttons in each row with unique id. Activity B also have same recyclerview but with some filter mechanism so it is not going to show all row, my question is how to handle like button state in Activity A and Activity B, such that if I click on activity B's like button than activity A's like button will automatically gets checked and vice versa.
You should use common data source for both the recycler views.
- Get data from API
- Save data in your local db
- Feed the data to your Activity A recycler view
- Feed the same data to your Activity B recycler view
- All the changes you make to data should be in local db so both the views can update automatically.
这篇关于在两个回收者视图与两个活动之间同步数据的最佳模式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!