我如何在android中使用countDown计时器

时间:2017-06-03 07:06:04

标签: android android-timer

我想在我的应用程序中使用 countDown 计时器,我应该创建如下: Click too see image

如何创建countDownTimer,如上面的设计?

3 个答案:

答案 0 :(得分:0)

在文本字段中显示30秒倒计时的示例:

new CountDownTimer(30000, 1000) {

    public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
    }

    public void onFinish() {
         mTextField.setText("done!");
    }

}.start();

访问https://developer.android.com/reference/android/os/CountDownTimer.html

答案 1 :(得分:0)

也许这可以帮助您:

https://github.com/tsuryo/Android-Countdown-Timer

-inf

和Java:

None

答案 2 :(得分:0)

private void downTimer(){
    new CountDownTimer(120*1000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            long second = (millisUntilFinished / 1000) % 60;
            long minutes = (millisUntilFinished/(1000*60)) % 60;
            textViewCountDownTimer.setText(minutes + ":" + second);
        }

        @Override
        public void onFinish() {
            textViewCountDownTimer.setText("Finish");
        }
    }.start();
}