Android countdown

前端 未结 3 2583
抹茶落季
抹茶落季 2021-02-20 18:11

I want to write a countdown in android which starts counting from 3 to 0. Like at first 3 in appearing and then disappearing and 2 is appearing and so on. I searched a lot but I

3条回答
  •  梦谈多话
    2021-02-20 18:51

    use CountDownTimer

    For example:

    import android.os.CountDownTimer;   
    
    MyCount timerCount;
    public class TestCountdown extends Activity {
    
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        timerCount = new MyCount(3 * 1000, 1000);
        timerCount.start();
      }
    
      public class MyCount extends CountDownTimer {
          public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
          }
    
          @Override
          public void onFinish() {
            //some script here
          }
    
          @Override
          public void onTick(long millisUntilFinished) {
            //some script here 
          }   
        } 
    }
    

提交回复
热议问题