package com.example.my.galgu;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
long first=1, second=1, answer;
boolean a=false ,s=false ,m=false ,d=false;
int i=0;
String wholesome, goti;
Button ba, bs, bm, bd, be;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
ba = (Button) findViewById(R.id.ba);
bs = (Button) findViewById(R.id.bs);
bm = (Button) findViewById(R.id.bm);
bd = (Button) findViewById(R.id.bd);
be = (Button) findViewById(R.id.be);
be.setEnabled(false);
}
public void disable(){
ba.setEnabled(false);
bs.setEnabled(false);
bm.setEnabled(false);
bd.setEnabled(false);
}
每个按钮从一到零的方法。 问题在于下面的方法,其中第一和第二 存储。该方法首先检查是否有+, - ,*,/按钮 按下然后将值存储在第一个或第二个变量中。 省略第一个变量的最后一位。我无法说出原因。
public void onone(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 1;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("1");
else{
textView.setText(wholesome + "1");
}
}
public void ontwo(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 2;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("2");
else{
textView.setText(wholesome + "2");
}
}
public void onthree(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 3;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("3");
else{
textView.setText(wholesome + "3");
}
}
public void onfour(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 4;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("4");
else{
textView.setText(wholesome + "4");
}
}
public void onfive(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 5;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("5");
else{
textView.setText(wholesome + "5");
}
}
public void onsix(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 6;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("6");
else{
textView.setText(wholesome + "6");
}
}
public void onseven(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 7;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("7");
else{
textView.setText(wholesome + "7");
}
}
public void oneight(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 8;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("8");
else{
textView.setText(wholesome + "8");
}
}
public void onnine(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 9;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("9");
else{
textView.setText(wholesome + "9");
}
}
public void onzero(View view){
if(a||s||m||d){
second *= i;
i = i * 10;
second += 1;
}else{
first = Integer.parseInt(textView.getText().toString());
}
wholesome = textView.getText().toString();
if(wholesome.equals("0"))
textView.setText("0");
else{
textView.setText(wholesome + "0");
}
}
public void ona(View view){
a = true;
wholesome = textView.getText().toString();
textView.setText(wholesome + "+");
disable();
be.setEnabled(true);
}
public void ons(View view){
s = true;
wholesome = textView.getText().toString();
textView.setText(wholesome + "-");
disable();
be.setEnabled(true);
}
public void onm(View view){
m = true;
wholesome = textView.getText().toString();
textView.setText(wholesome + "*");
disable();
be.setEnabled(true);
}
public void ond(View view){
d = true;
wholesome = textView.getText().toString();
textView.setText(wholesome + "/");
disable();
be.setEnabled(true);
}
public void one(View view){
if(a){
answer = first + second;
}
else if (s){
answer = first - second;
}
else if (m){
answer = first * second;
}
else if (d){
answer = first / second;
}
goti = String.valueOf(answer);
textView.setText(goti);
second = 1;
i = 0;
a = false;
s = false;
m = false;
d = false;
ba.setEnabled(true);
bs.setEnabled(true);
bm.setEnabled(true);
bd.setEnabled(true);
}
public void once(View view){
textView.setText("0");
second = 1;
i = 0;
ba.setEnabled(true);
bs.setEnabled(true);
bm.setEnabled(true);
bd.setEnabled(true);
be.setEnabled(false);
a = false;
s = false;
m = false;
d = false;
}
}