Chronometer countdown in android

Sameer Z. picture Sameer Z. · Feb 10, 2012 · Viewed 10k times · Source

I have implemented a simple chronometer from the android api demo. Now is it possible to show the countdown in chronometer like setting the start to 01:23 then onClick of start button, it will change to 01:22 then 01:21 and so on... till 00:00. Please let me know if anyone did it before. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ChronometerDemo.html

Thank you.

Answer

kaneda picture kaneda · Oct 19, 2012

For those who are interested, take a look at CountDownTimer class.

Example:

new CountDownTimer(30000, 1000) {

 public void onTick(long millisUntilFinished) {
     mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
 }

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