Android MVC Demo Sample reference, basically very clear and standard

Source: Internet
Author: User

Android MVC Demo Sample reference, basically very clear and standard


MVC is the separation of V (View) and M (Model) through C (Controller), which reduces the degree of coupling.


Here is a specification for the Android MVC reference that you write yourself:


Project structure:



Layout xml (Activity_main.xml):


<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: Context= ". Mainactivity "> <button android:id=" @+id/btn "android:layout_width=" Wrap_content "Android:la         yout_height= "Wrap_content" android:layout_centerinparent= "true" android:text= "MVC load Data"/> <textview        Android:id= "@+id/tv_view" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:layout_below= "@id/btn" android:layout_margintop= "10DP"/></relativelayout>

Mainactivity.java


Package Com.tandong.androidmvc;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;import Com.tandong.androidmvc.r;import Com.tandong.androidmvc.base.baseactivity;import Com.tandong.androidmvc.implement.mainimplement;import Com.tandong.androidmvc.model.mainmodel;public Class Mainactivity extends Baseactivity implements Mainimplement,onclicklistener {private Button btn;private TextView Tv_view ;p rivate mainmodel Mmodel; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); Mmodel = new Mainmodel (); btn = (Button) This.findviewbyid (r.id.btn); Tv_view = (TextView) This.findviewbyid (R.id.tv_view); Btn.setonclicklistener (this);} @Overridepublic void LoadData () {mmodel.loaddata (Tv_view);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {case r.id.btn:loaddata (); break;default:break;}}}

Baseactivity.java


Package Com.tandong.androidmvc.base;import Android.app.activity;import Android.os.bundle;public class BaseActivity Extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate);}}

Mainimplement.java


Package Com.tandong.androidmvc.implement;public interface Mainimplement {public void loaddata ();

Mainmodel.java


Package Com.tandong.androidmvc.model;import Android.widget.textview;public class Mainmodel {public void LoadData ( TextView Tv_view) {tv_view.settext ("MVC mode application in Android, get data processed in Model");}}

This realizes the logical realization and the interface separation.


Tan Dong

qq:852041173




Android MVC Demo Sample reference, basically very clear and standard

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.