Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a countdown timer in Android?

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?

like image 543
Sabbir Ahmed Avatar asked Apr 05 '12 16:04

Sabbir Ahmed


People also ask

Is there a timer widget for Android?

The great thing about the Android timer apps is that they don't just count down seconds, but it also has widgets placed on the home screen. That means you can access the timer feature without opening the app itself.


1 Answers

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.

like image 168
Shankar Agarwal Avatar answered Oct 09 '22 06:10

Shankar Agarwal