Search code examples
androidandroid-support-librarychronometer

Support Library for Chronometer in Android


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


Solution

  • 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