2016-02-26 37 views
0

我試圖通過Mainactivity作爲以主持人Android的MVP模式通過上下文視圖

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

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

然而,這種拋錯誤這是無效的鑄造或東西。 我錯過了什麼嗎?

該代碼是從here

+0

你實現'MainPresenter.View'在MainActivity? – Nfear

+0

我需要創建嗎?或其內置的界面? – user3882878

回答

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(); 
    }