public void doWhenItem1IsClicked(){
mView.showRelevantPageOnMainScreen()
}
----------------------查看1 ---------------------
public void showRelevantPageOnMainScreen(){
View2 view2=new View2(); //This is better to be done using DI
getFragmentManager().beginTransaction().replace(R.id.your_main_page_layout,view2).commit();
}
----------------------查看2 ---------------------
public void onCreate(){
super.onCreate();
presenter2=new Presenter2(this);
}
.
.
.
2 回答
首先,在MVP方法中,演示者和视图彼此之间具有1对1的关系 . 如果您想使用EventBus / RxBus等总线系统在演示者之间进行通信 .
我推荐以下教程 . 这是一个由5部分组成的系列教程 . 在本教程中,有两个片段(搜索和缓存片段)彼此之间进行通信 .
https://hackernoon.com/yet-another-mvp-article-part-1-lets-get-to-know-the-project-d3fd553b3e21
在MVP中,View使用
Context
来启动另一个View,它是另一个Fragment
或Activity
,因此Fragments
之间的任何转换都必须通过View . 在您的情况下,您有:View1(滑动抽屉碎片)<-----> Presenter1
View2(主片段)<-----> Presenter2
您单击View1上的小部件,并希望使用MVP导航到View2上的某个屏幕 . 你可以这样做:
----------------------查看1 ---------------------
----------------------演示者1 ----------------
----------------------查看1 ---------------------
----------------------查看2 ---------------------
我写了一个MVP库here你可能会觉得有帮助 .