在两个回收者视图与两个活动之间同步数据的最佳模式是什么? [英] What is the best pattern to sync data between two recycler view with two activities?

查看:251
本文介绍了在两个回收者视图与两个活动之间同步数据的最佳模式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动,他们几乎相同的数据,我使用相同的适配器,但问题是如何同步数据。



例如。
活动A 具有 recyclelerview ,其中每行具有唯一ID的按钮。 活动B 还具有相同的回收器视图,但使用一些过滤器机制,因此不会显示所有行,我的问题是如何处理像按钮状态为活动A 活动B ,以便如果我点击活动B,如按钮活动A类似按钮将自动检查,反之亦然。

解决方案

您应该为回收者视图使用通用数据源。


  1. 从API获取数据

  2. 将数据保存在本地数据库中

  3. 将数据提供给您的活动A回收商视图

  4. 将相同的数据提供给您的活动B回收商视图

  5. 您对数据所做的所有更改应为在本地数据库中,所以
    视图都可以自动更新。


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.

  1. Get data from API
  2. Save data in your local db
  3. Feed the data to your Activity A recycler view
  4. Feed the same data to your Activity B recycler view
  5. All the changes you make to data should be in local db so both the views can update automatically.

这篇关于在两个回收者视图与两个活动之间同步数据的最佳模式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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