Android简单的加法计算器

Android简单的加法计算器_第1张图片

package com.example.calculator;

import android.os.Bundle;
import android.app.Activity;
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 {

	private TextView tv1;
	private EditText et1;
	private EditText et2;
	private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv1 =  (TextView)  this.findViewById(R.id.textView1);
        et1 = (EditText)  this.findViewById(R.id.editText1);
        et2 = (EditText)  this.findViewById(R.id.editText2);
        btn = (Button)    this.findViewById(R.id.button1);
        btn.setOnClickListener(new View.OnClickListener() {
		
		@Override
			public void onClick(View v) {
			  String inputText1 = et1.getText().toString();
              String inputText2 = et2.getText().toString();
              int num1 = Integer.valueOf(inputText1).intValue();
              int num2 = Integer.valueOf(inputText2).intValue();
              num1 = num1+num2;
              inputText1 = String.valueOf(num1);
           
              tv1.setText(inputText1);
			
		}
		});
	
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}



你可能感兴趣的:(Andrioid)