android Mvp模式传递上下文作为视图

时间:2016-02-26 14:06:02

标签: android mvp

我试图将Mainactivity作为视图传递给演示者

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

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

但是,这个抛出错误是无效的铸造之类的东西。 我错过了什么吗?

该代码来自here

1 个答案:

答案 0 :(得分:1)

你应该有类似的东西:

public interface YourView {
    void doSomething();
}

public MainActivity extends Activity implements YourView {

mainPresenter = new MainPresenter(this);

}

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