How to make a countdown timer in Android?

Sabbir Ahmed picture Sabbir Ahmed · Apr 5, 2012 · Viewed 295.9k times · Source

I have two EditTexts in XML. In one EditText, the user can put a number as minutes and in another EditText, a number as seconds. After clicking the finish button, the seconds EditText should start to countdown and update its text every second.

Additionally, how can I keep it updating until it gets to zero minutes and zero seconds?

Answer

Shankar Agarwal picture Shankar Agarwal · Apr 5, 2012
new CountDownTimer(30000, 1000) {

    public void onTick(long millisUntilFinished) {
        mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
       //here you can have your logic to set text to edittext
    }

    public void onFinish() {
        mTextField.setText("done!");
    }

}.start();

Refer to this link.