标签:
package com.example.sum;//sum import com.example.sum.R;//sum import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView;//导入各种包 //public class MainActivity extends Activity { public class MainActivity extends Activity implements View.OnClickListener {//一个view监听点击事件 private EditText editText;//定义私有变量 private EditText editText1;//定义私有变量 private TextView textView; @Override public void onCreate(Bundle savedInstanceState) { //数据绑定函数 super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);//显示主页面 findViewById(R.id.button1).setOnClickListener(this);//找到按钮的id,设置点击监听 editText = (EditText) findViewById(R.id.editText2);//找到编辑框的id,赋值给edittext textView = (TextView) findViewById(R.id.textView1);//找到textview的id,赋值 editText1 = (EditText) findViewById(R.id.editText1);//找到编辑框的id,赋值给edittext } // public void OnMySelfClick(View v) //{ //} /* (non-Javadoc) * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) {//点击事件函数 textView.setText(String.valueOf(Integer.parseInt(editText.getText().toString().trim())+Integer.parseInt(editText1.getText().toString().trim()))); //编辑框先强制转化为字符串型再转化为整形,整形相加,它们的和转化为字符串型被用来显示,setText接收字符串 } } //}
http://mobile.qzone.qq.com/l?g=1357&sharekey=bbe21efec5ad82d93bface37bad9e52c
标签:
原文地址:http://www.cnblogs.com/hellowzd/p/4223582.html