Android MVC Demo example reference, basically clear and standard, androidmvc

Source: Internet
Author: User

Android MVC Demo example reference, basically clear and standard, androidmvc

Android MVC Demo example reference, basically clear and standard


MVC separates V (View) and M (Model) through C (Controller) to reduce coupling.


Here is a reference specification for Android MVC:


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: paddingBottom = "@ dimen/activity_vertical_margin" android: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/plugin" tools: context = ". mainActivity "> <Button android: id =" @ + id/btn "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: layout_centerInParent =" true "android: text = "MVC loading 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;private 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 ("Application of MVC mode in Android, data processed in the Model obtained ");}}

In this way, the logical implementation and interface are separated.


Author: Tan Dong

QQ: 852041173




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.