MVC模式入门案例

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView; public class MainActivity extends Activity implements MainImplement,
View.OnClickListener {
private Button btn;
private TextView tv_view;
private MainModel mModel;
@Override
protected 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);
}
@Override
public void loadData() {
mModel.loadData(tv_view);
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn:
loadData();
break; default:
break;
}
}
}


public interface  MainImplement {
public void loadData();
}

import android.widget.TextView;
public class MainModel {
public void loadData(TextView tv_view) {
tv_view.setText("MVC模式在Android中的应用,获取到的Model中处理的数据");
}
}
上一篇:手机打开PDF文档中文英文支持(乱码问题)解决攻略


下一篇:Git在已有的分支上新建个人分支开发