There is a timer (registered in OnCreate):
CountDownTimer timer; timer = new CountDownTimer(10000, 1000) { public void onTick(long millisUntilFinished) { text_d1.setText("Осталось: "+ millisUntilFinished / 1000); public void onFinish() { text_d1.setText("Время вышло"); } }.start(); There is a keystroke processing method on the virtual keyboard:
public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER)) { // тут разные условия, в зависимости от того, в каком edittext нажата клавиша ввод return true; } return false; } The logic is as follows:
As soon as the activation is opened, the timer starts.
The timer automatically stops after 10 seconds.
How to add a condition that the timer also stops if the key on the keyboard is pressed?
timer.cancel()in the enter key processing method - pavlofff