I am writing a calculator on android, but I can’t do the function of percent and exponentiation (any number to any), because after pressing the button itself, the program immediately counts (assigns the value of the second variable to 0), and must wait for the second variable to be entered from the buttons (keyboard) .
Of course, I use the Math.pow(a,b) method (for exponentiation) and the buttonExponentiation button is in the general switch/case .
How to make this delay (so that the button waits for the input of the second variable)?
public void onClick(View view) { switch (view.getId()) { case R.id.button1: ClickNumber(1); break; case R.id.button2: ClickNumber(2); break; case R.id.button3: ClickNumber(3); break; case R.id.button4: ClickNumber(4); break; case R.id.button5: ClickNumber(5); break; case R.id.button6: ClickNumber(6); break; case R.id.button7: ClickNumber(7); break; case R.id.button8: ClickNumber(8); break; case R.id.button9: ClickNumber(9); break; case R.id.button0: ClickNumber(0); break; case R.id.buttonAdd: if (flagAction == 0) flagAction = 1; break; case R.id.buttonSub: if (flagAction == 0) flagAction = 2; break; case R.id.buttonMult: if (flagAction == 0) flagAction = 3; break; case R.id.buttonDiv: if (flagAction == 0) flagAction = 4; break; case R.id.buttonEq: switch (flagAction) { case 1: result = operand1 + operand2; showNumber(result); operand1 = result; break; case 2: result = operand1 - operand2; showNumber(result); operand1 = result; break; case 3: result = operand1 * operand2; showNumber(result); operand1 = result; break; case 4: result = operand1 / operand2; showNumber(result); operand1 = result; break; default: Toast.makeText(this, "Вкажіть дію!", Toast.LENGTH_LONG).show(); } if (flagAction != 0) { showNumber(result); clearVariables_2(); } break; case R.id.buttonClean: clearVariables(); showNumber(operand1); break; case R.id.buttonComa: break; case R.id.buttonSquare: if (flagAction == 0) { result = Math.pow(operand1, 2); showNumber(result); // clearVariables_2(); operand1 = result; } else { Toast.makeText(this, R.string.other_operation, Toast.LENGTH_LONG).show(); } break; case R.id.buttonSqrt: if (flagAction == 0) { result = Math.sqrt(operand1); showNumber(result); operand1 = result; } else { Toast.makeText(this, R.string.other_operation, Toast.LENGTH_LONG).show(); } break; case R.id.buttonBack: // !!!!!!!!!!!!!! NULL WHY ??????????? String Temp = null; if (flagAction == 0) { if (operand1 % 1 == 0) { Temp = Integer.toString((int) operand1); } else { Temp = Double.toString(operand1); } Temp = Temp.substring(0, Temp.length() - 1); if (Temp.length() > 0) { operand1 = Double.parseDouble(Temp); } else { operand1 = 0; } showNumber(operand1); } else { if (flagAction == 0) { if (operand2 % 1 == 0) { Temp = Integer.toString((int) operand2); } } else { Temp = Double.toString(operand2); } Temp = Temp.substring(0, Temp.length() - 1); if (Temp.length() > 0) { operand2 = Double.parseDouble(Temp); } else { operand2 = 0; } showNumber(operand2); } break; case R.id.buttonOff: finish(); break; case R.id.buttonExponentiation: if (flagAction == 0) { if(operand1 != 0){ // some code .................. } result = Math.pow(operand1, operand2); showNumber(result); } else { Toast.makeText(this, R.string.other_operation, Toast.LENGTH_LONG).show(); } break; case R.id.buttonPercent: result = operand1 * 100 / operand2; showNumber(result); break; } }