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