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实现倒计时功能的。



  • 相关阅读:
    【转】Windows守护进程的一种简单实现
    vim 文本会在末尾自动添加换行 md5文件和数据只不对应
    指向指针的指针的理解和应用
    TinyXML C++解析XML
    加密解密 AES RSA MD5 SHA
    微信支付 php兼容问题
    sublime text 2 php 语法错误检查
    微信支付宝支付
    MySql安装和基本管理
    验证码处理
  • 原文地址:https://www.cnblogs.com/mbp-study/p/6547223.html
Copyright © 2011-2022 走看看