简体   繁体   English

Android中的MVP-如何在演示者之间交换数据/事件?

[英]MVP in Android - How to Exchange data/events between Presenters?

I am wondering how you do exchange data or/and events between Presenters in Model-View-Presenter architecture. 我想知道您如何在Model-View-Presenter体系结构中的Presenters之间交换数据或/和事件。

I have Activity(View) and Presenter for this View, and Dialog(View) and Presenter for this View. 我有该视图的Activity(视图)和Presenter,以及该视图的Dialog(View)和Presenter。 When Activity shows Dialog, Dialog's Presenter is injected to Dialog. 当“活动”显示“对话框”时,“对话框的演示者”将注入到“对话框”中。 I am doing something in Dialog (input text) and submit. 我正在Dialog(输入文本)中做某事并提交。 This text is seted in presenter, and ... exactly. 该文本是在演示者中设置的,并且...完全一样。 How to pass this data from Dialog's Presenter to Activity's Presenter? 如何将这些数据从Dialog的Presenter传递给Activity的Presenter?

I used Bus Event (Otto form Square) to send data, but if it is good practice? 我使用Bus Event(Otto形式的Square)发送数据,但是这是一种好习惯吗?

The solution is simple - it is the "M" in "MVP". 解决方案很简单-它是“ MVP”中的“ M”。 Use your model to sync your data across the presenters. 使用您的模型在演示者之间同步数据。 If you need a notifier for data changes, there are plenty of possible solutions: 如果您需要数据更改的通知者,则有很多可能的解决方案:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM