![](/img/trans.png)
[英]Is a bad practice passing references of a View to a Presenter in MVP Pattern?
[英]android Mvp pattern passing context as view
我试图将Mainactivity作为视图传递给演示者
(In MainActivity)
mainPresenter = new MainPresenter(this);
(Presenter cont)
public MainPresenter(View view) {
this.view = view;
user = new User();
}
但是,此抛出错误是无效的转换或其他错误。 我想念什么吗?
该代码是从这里
你应该有这样的东西:
public interface YourView {
void doSomething();
}
public MainActivity extends Activity implements YourView {
mainPresenter = new MainPresenter(this);
}
public MainPresenter(YourView view) {
this.view = view;
view.doSomething();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.