![](/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.