If there any support Library function that could make the setCountDown
function of the chronometer support by APIs lower than 24?

- 8,084
- 8
- 48
- 62

- 125
- 1
- 13
-
How about copy-pasting sources of API 24 into your project and using that `Chronometer` instead? – azizbekian Jan 18 '18 at 07:16
-
can you elaborate ? – Wali Muhammad Khubaib Jan 18 '18 at 09:03
-
What about copy pasting [this](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/Chronometer.java) class into your package and use `com.your.package.Chronometer` class instead of `android.widget.Chronometer`. – azizbekian Jan 18 '18 at 09:19
-
tried but didn't work – Wali Muhammad Khubaib Jan 18 '18 at 09:52
-
`tried but didn't work` What exactly didn't work? – azizbekian Jan 18 '18 at 09:54
-
You also have to copy the string resources. They're in
/platforms/android-XX/data/res/values and values-YY based on language you want. – Eugen Pechanec Jan 21 '18 at 21:24
2 Answers
You can try RXJava to simple handle threads, timers, and many other functionalities.
The documentation for the timer operator says this:
Create an Observable that emits a particular item after a given delay
Thus the behavior you are observing is expected- timer() emits just a single item after a delay.
The interval operator, on the other hand, will emit items spaced out with a given interval.
For example, this Observable will emit an item every second:
Observable.interval(1, TimeUnit.SECONDS);
And an complete example:
Observable.interval(1,TimeUnit.SECONDS, Schedulers.io())
.take(300) // take 300 second
.map(v -> 300 - v)
.subscribe(
onNext -> {
//on every second pass trigger
},
onError -> {
//do on error
},
() -> {
//do on complete
},
onSubscribe -> {
//do once on subscription
});

- 3,860
- 4
- 32
- 63
According to Android Documentation , its not possible with below API level 24. Chronometer widget only use count up. If you need to do so go with CountDownTimer.
For Example:
final int oneSecond = 1000; // in milliSeconds i.e. 1 second
final int tenSeconds = 100000; // 100 seconds
CountDownTimer cTimer = new CountDownTimer(100000, oneSecond) {
public void onTick(long millisUntilFinished) {
int totalTime = 60000; // in milliseconds i.e. 60 seconds
String v = String.format("%02d", millisUntilFinished/totalTime);
int va = (int)( (millisUntilFinished%totalTime)/oneSecond);
textView.setText("remaining seconds: " +v+":"+String.format("%02d",va));
}
public void onFinish() {
textView.setText("done!");
}
};
cTimer.start();
EDIT:
If you want to go with GitHub Solution then have a look at this and this

- 8,577
- 7
- 33
- 60