简体   繁体   中英

android Mvp pattern passing context as view

I have tried to pass Mainactivity as view to presenter

(In MainActivity)    
mainPresenter = new MainPresenter(this);

(Presenter cont)
public MainPresenter(View view) {
      this.view = view;
      user  = new User();
   }

However, this throw error which is invalid casting or something. Am I missing something?

That code is from here

You should have something like that :

public interface YourView {
    void doSomething();
}

public MainActivity extends Activity implements YourView {

mainPresenter = new MainPresenter(this);

}

public MainPresenter(YourView view) {
      this.view = view;
      view.doSomething();
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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