zoukankan      html  css  js  c++  java
  • CountDownTimer

    Schedule a countdown until a time in the future, with regular notifications on intervals along the way. Example of showing a 30 second countdown in a text field:

    new CountDownTimer(30000, 1000) {
    
         public void onTick(long millisUntilFinished) {
             mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
         }
    
         public void onFinish() {
             mTextField.setText("done!");
         }
      }.start();

    The calls to onTick(long) are synchronized to this object so that one call to onTick(long) won't ever occur before the previous callback is complete. This is only relevant when the implementation of onTick(long) takes an amount of time to execute that is significant compared to the countdown interval.

    Public constructors

    CountDownTimer (long millisInFuture, long countDownInterval)
    millisInFuture----long: The number of millis in the future from the call to start() until 
    the countdown is done and onFinish() is called. countDownInterval----long: The interval along the way to receive onTick(long) callbacks.

    Public methods

    (1)cancel----void cancel ()

    Cancel the countdown.

    (2)onFinish----void onFinish ()

    Callback fired when the time is up.

    (3)onTick----void onTick (long millisUntilFinished)

    Callback fired on regular interval.

    (4)start----CountDownTimer start ()

    Start the countdown.

    理解:

    CountDownTimer----android倒计时方法

    从官方文档的代码可以看出CountDownTimer每隔1秒调用一次onTick(long millisUntilFinished)方法,倒计时介绍时调用onFinish()方法.

    • 方法1----cancel(): 取消当前的任务
    • 方法2----onFinish(): 当前任务完成的时候回调
    • 方法3----onTick(long millisUntilFinished): 当前任务每完成一次倒计时间隔时间时回调
    • 方法4----start(): 开始当前的任务

    从CountDownTimer的源码可以知道,他并不是一个完整的计时器,是通过handler实现倒计时功能的。



  • 相关阅读:
    random模块的随机变换
    re模块与正则表达式进阶
    面向对象整体细化
    __new__内部工作方式
    前端之CSS
    前端之HTML
    数据库
    同步异步阻塞非阻塞
    进程间的通信
    day 36(多进程)
  • 原文地址:https://www.cnblogs.com/mbp-study/p/6547223.html
Copyright © 2011-2022 走看看