demo04calc

package com.example.demo05simplecalc;

import android.os.Bundle;
import android.app.Activity;
import android.speech.tts.TextToSpeech;
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 int no1=0;
    private int no2=0;

    private EditText editText1=null;
    private EditText editText2=null;

    private Button btnAdd=null;
    private Button btnSub=null;
    private Button btnMul=null;
    private Button btnDiv=null;

    private TextView fuhao=null;
    private TextView jieguo=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.editText1 = (EditText) super.findViewById(R.id.no1);
        this.editText2 = (EditText)super.findViewById(R.id.no2);

        this.editText1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.this.editText1.setText("");
            }
        });

        this.editText2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.this.editText2.setText("");
            }
        });


        this.btnAdd = (Button) super.findViewById(R.id.btnAdd);
        this.btnSub = (Button)super.findViewById(R.id.btnSub);
        this.btnMul = (Button)super.findViewById(R.id.btnMul);
        this.btnDiv = (Button)super.findViewById(R.id.btnDel);

        this.btnAdd.setOnClickListener(new AddListener());
        this.btnSub.setOnClickListener(new SubListener());
        this.btnMul.setOnClickListener(new MulListener());
        this.btnDiv.setOnClickListener(new DivListener());


        this.fuhao=(TextView)super.findViewById(R.id.fuhao);
        this.jieguo=(TextView)super.findViewById(R.id.jieguo);


    }

    private class AddListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
            MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());

            MainActivity.this.fuhao.setText("+");
            MainActivity.this.jieguo.setText(String.valueOf(no1+no2));
        }
    };

    private class SubListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
            MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());

            MainActivity.this.fuhao.setText("-");
            MainActivity.this.jieguo.setText(String.valueOf(no1-no2));
        }
    };

    private class MulListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
            MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());

            MainActivity.this.fuhao.setText("*");
            MainActivity.this.jieguo.setText(String.valueOf(no1*no2));
        }
    };

    private class DivListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            MainActivity.this.no1 =Integer.parseInt( MainActivity.this.editText1.getText().toString());
            MainActivity.this.no2 =Integer.parseInt( MainActivity.this.editText2.getText().toString());

            MainActivity.this.fuhao.setText("/");
            MainActivity.this.jieguo.setText(String.valueOf(no1/no2));
        }
    };

//    @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;
//    }
    
}

 

posted @ 2016-03-02 23:00  Alamps  阅读(212)  评论(1编辑  收藏  举报