Extended AndroidAnnotations using MVP Mode Programming
Code on
Activity implements a set of interfaces to operate views.
Public class MainActivity extends Activity implements TestView {// P in MVP, one View can have multiple P to implement multiple business logic, for example, you need to read the Conversation content @ Bean (TestActions. class) ITestActions testActions; @ ViewById (R. id. btn_back) Button btnBack; @ ViewById (R. id. btn_noback) Button btnNoback; // TestView interface, used for interface display. Because Actions may be called in the thread, UIThread Security @ UiThread @ Overridepublic void showName (String name) {Toast. makeText (this, name, Toast. LENGTH_SHORT ). show (); btnBack. setText ("clicked");} // event 1 @ Click (R. id. btn_back) public void doInback () {testActions. doInbackground ();} // event 2 @ Click (R. id. btn_noback) public void doNoBack () {testActions. doNoback ();}}
View Interface can implement multiple
TestActions implements business logic and injects the TestView interface for callback display.
@ EBeanpublic class TestActions implements ITestActions {** // automatically injects the UI View, Fragment, or Activity. You can also add multiple views in P. Different views correspond to different modules, this label is extended and used to inject the View Interface ** @ ViewInterfaceTestView view; // Method 1: run by thread, background task @ Override @ Backgroundpublic void doInbackground () {// do some business here and call the showName of View to display it to UIview. showName ("show in back ground2");} // method 2, run @ Overridepublic void doNoback () {view in the main UI thread. showName ("show in no back ");}}
TestView Interface
public void showName(String name);