Extended AndroidAnnotations using MVP Mode Programming

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.