On the MVC pattern in Android

Source: Internet
Author: User

MVC is the abbreviation of model, view, controller. Android encourages weak coupling and component reuse, and the specific embodiment of MVC in Android is as follows:

model: is the subject part of the application, all the business logic should be in the layer (operation of the database, the network, etc. should be processed in the model, of course, the calculation and other operations must be placed on the layer).

View Layer: Is the part of the application that is responsible for generating the user interface. It is also the only layer that the user can see in the entire MVC architecture, receiving input from the user and displaying the user's processing results. The general use of XML file interface description, when used can be very convenient to introduce.

Control Layer (Controller): Controls the display of user interface data and the state of a new model object based on user input. The task of Android's control layer usually falls on the shoulders of many activities, which implies not to write too much code in activity, to deal with it through activity delivery model business logic processing layer, Another reason for this is that activity in Android has a response time of 5 seconds, and the program can easily be recycled if time-consuming operations are put here.

Here's a case for a brief introduction to the subcontracting layering in Android projects:



 PackageCom.dy.mvctest.base;ImportAndroid.os.Bundle;ImportAndroid.support.v7.app.AppCompatActivity;/*** Created by Dy on 2016/5/9. */Public abstract classBaseactivityextendsappcompatactivity {@Override    protected voidonCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (Setviewid ());        Findviews ();        Init ();        Initevents ();        Loaddatas ();    }/**     * SetLayoutof ResourcesID     *     * @return     */    protected Abstract intSetviewid();    /**     * Find child controls     */    protected abstract voidfindviews();    /**     * Initialize     */    protected abstract voidInit();    /**     * setting up event snooping     */    protected abstract voidinitevents();    /**     * Loading Data     */    protected abstract voidLoaddatas();}



 PackageCom.dy.mvctest.base;ImportAndroid.os.Bundle;ImportAndroid.support.v4.app.Fragment;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;/*** Created by Dy on 2016/5/9. */Public abstract classBasefragmentextendsFragment {@Override     PublicViewOncreateview(Layoutinflater Inflater, ViewGroup container, Bundle savedinstancestate) {//Return Super.oncreateview (Inflater, container, savedinstancestate);        View view = Inflater.inflate (Setviewid (), Container, False);        Findviews (view);        Init ();        Initevent ();        Loaddatas ();returnView;    }/**     * Set up ResourcesID     *     * @return     */    protected Abstract intSetviewid();    /**     * Find child controls     */    protected abstract voidfindviews(View view);    /**     * Initialize     */    protected abstract voidInit();    /**     * setting up event snooping     */    protected abstract voidinitevent();    /**     * Loading Data     */    protected abstract voidLoaddatas();}

Continue tomorrow ....



On the MVC pattern in Android

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.