demo04calc

Posted Alamps 沁园春

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
//    }
    
}

 

以上是关于demo04calc的主要内容,如果未能解决你的问题,请参考以下文章

JAVA实现随机四则运算

CSS3的calc()用法简单介绍

[vscode]--HTML代码片段(基础版,reactvuejquery)

CSS Calc 替代方案

12mmaction2 行为识别商用级别X3D复现 demo实现 检测自己的视频 Expanding Architecturesfor Efficient Video Recognition(代码片段

[异常解决] Keil安装好nRF51822开发环境,运行DEMO报错:Error:“GPIOTE_CONFIG_NUM_OF_LOW_POWER_ENVENTS” is undefined(代码片段