package com.example.sum;//sum import com.example.sum.R;//sum import android.app.Activity; import android.view.View.OnClickListener; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;//导入各种包 public class MainActivity extends Activity { //import android.content.DialogInterface; Button button1 = (Button) findViewById(R.id.button1); Button button2 = (Button) findViewById(R.id.button2); EditText editText1 = (EditText) findViewById(R.id.editText1);//找到编辑框的id,赋值给edittext EditText editText2 = (EditText) findViewById(R.id.editText2);//找到textview的id,赋值 EditText editText3 = (EditText) findViewById(R.id.editText3);//找到编辑框的id,赋值给edittext TextView textView = (TextView) findViewById(R.id.textView1); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1.setOnClickListener(new OnClickListener() { public void onClick(View v) { textView.setText(String.valueOf(Integer.parseInt(editText1.getText().toString().trim())+Integer.parseInt(editText2.getText().toString().trim())+Integer.parseInt(editText3.getText().toString().trim()))); } }); button2.setOnClickListener(new OnClickListener() { public void onClick(View v) { editText3.setText(button2.getText()); } }); } }