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



  • 相关阅读:
    渲染机制
    CSS渲染速度改善的十个方法与建议
    HTML你应该知道的三大基本元素
    链接属性rel=’external’、rel=’nofollow’、rel=’external nofollow’三种写法的区别
    rel=nofollow
    CSS3 圆形时钟式网页进度条
    @media screen解决移动web开发的多分辨率问题
    meta 标签属性(网站兼容与优化需要)
    如何解决谷歌浏览器下jquery无法获取图片的尺寸
    CSS设计之页面滚动条出现时防止页面跳动的方法
  • 原文地址:https://www.cnblogs.com/mbp-study/p/6547223.html
Copyright © 2011-2022 走看看