Support Library for Android Chronometer

If there is any library support function that can make the setCountDownchronometer support function an API below 24?

+6
source share
2 answers

According to the Android documentation, this is not possible with an API level below 24. Chronometer only use counting. If you need to do this, go to CountDownTimer .

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 a GitHub solution, check out this and this

0
source

RXJava , .

:

,

, , , - timer() .

, , , .

, Observable :

Observable.interval(1, TimeUnit.SECONDS);

:

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
            });
0

All Articles