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



  • 相关阅读:
    机房收费系统重构(三)—工厂+反射+DAL
    机房收费系统重构(二)—菜鸟入门
    机房收费系统重构(—)—小试牛刀
    vb.net机房收费登录功能
    设计模式总结之结构型模式
    设计模式总结之创建型模式
    大话设计之桥接模式
    大话设计之单例模式
    大话设计之适配器模式
    大话设计之抽象工厂模式
  • 原文地址:https://www.cnblogs.com/mbp-study/p/6547223.html
Copyright © 2011-2022 走看看