Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start chronometer in reverse in android?

Tags:

cmtr.setText(finalTime);
cmtr.setBase(SystemClock.elapsedRealtime());

timetest = SystemClock.elapsedRealtime();
Log.d("SETTIME: ", ""+timetest);
cmtr.start();

eltime = SystemClock.elapsedRealtime();
Log.d("ELapsed: ", ""+eltime);

Note: i want to start my chronometer in reverse order. like i set chronometer 10 seconds. now, i want to start from 10 to 0 seconds in reverse order. so can anyone help to get this solution.? Thank you so much in advance.

like image 507
Sagar Maiyad Avatar asked Mar 21 '13 20:03

Sagar Maiyad


1 Answers

You can't, the Chronometer widget only counts up, that's the specific purpose it was made for. If you want to count down, use the CountDownTimer (the Android SDK page contains a specific example where a TextView is updated), or roll your own solution.

These classes are trivial wrappers to save you some typing. You really shouldn't feel uncomfortable writing an alternative implementation if they don´t fit your exact needs.

[Update]

As Ronaldo Bahia added in the remarks, since API 24 the Chronometer actually offers this functionally through the setCountDown method.

like image 147
Paul-Jan Avatar answered Oct 09 '22 03:10

Paul-Jan