package com.example.sum;//sum import com.example.sum.R;//sum //import com.example.hello.R; import android.app.Activity; import android.view.View.OnClickListener; import android.os.Bundle; //import android.view.Menu; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; //import android.view.Menu; import android.view.View; //import android.widget.Button; //import android.widget.EditText; //import android.widget.TextView;//导入各种包 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button button1 = (Button) findViewById(R.id.button1);//final获得句柄 获得句柄 final Button button2 = (Button) findViewById(R.id.button2); final EditText editText1 = (EditText) findViewById(R.id.editText1); final EditText editText2 = (EditText) findViewById(R.id.editText2); final EditText editText3 = (EditText) findViewById(R.id.editText3); final TextView textView = (TextView) findViewById(R.id.textView1); button1.setOnClickListener(new OnClickListener() { public void onClick(View v) { String a=editText3.getText().toString().trim();//判断编辑框3是否为字符串加号 赋值 String b="+"; if (a.equals(b)){//如果编辑框3为字符串加号,那么执行加法运算 字符串比较 textView.setText(String.valueOf( Integer.parseInt(editText1.getText().toString().trim()) //控件转字符串,字符串转整形,整形转字符串 +Integer.parseInt(editText2.getText().toString().trim()) //去除空格 )); }else{ System.out.println("A"); } } }); //+Integer.parseFloa(editText3.getText().toString().trim()) button2.setOnClickListener(new OnClickListener() { public void onClick(View v) { editText3.setText(button2.getText()); } }); } }