zoukankan      html  css  js  c++  java
  • Android开发(五)——计时器

    发送验证码后倒计时,Android自带计时器CountDownTimer,重写自己的计时器以实现跟新View的效果。

    package com.lgaoxiao.widget;
    
    import android.os.CountDownTimer;
    import android.widget.TextView;
    
    /**
     * TextView的计时器
     * @author TimZhang
     *
     */
    public class MyCountTimer extends CountDownTimer {
        private TextView btn;
        private int normalColor,timingColor;
        private String normalText;
        
        /**
         * @param millisInFuture
         * @param countDownInterval
         * @param v TextView
         * @param nColor Normal Color
         * @param tColor Timing Color
         */
        public MyCountTimer(long millisInFuture, long countDownInterval,TextView v,int nColor,int tColor) {
            super(millisInFuture, countDownInterval);
            this.btn = v;
            this.normalColor = nColor;
            this.timingColor = tColor;
            this.normalText = v.getText().toString();
        }
    
        @Override
        public void onTick(long millisUntilFinished) {
            btn.setBackgroundColor(timingColor);
            btn.setEnabled(false);
            btn.setText(millisUntilFinished / 1000 + "s");
            
        }
    
        @Override
        public void onFinish() {
            btn.setEnabled(true);
            btn.setBackgroundColor(normalColor);
            btn.setText(normalText);
        }
    
    }

    参考:http://www.open-open.com/code/view/1426335036826

  • 相关阅读:
    linux系统缓存机制
    信号“未决”与“阻塞”
    异步I/O
    Unix下五种IO模型
    【设计模式
    【设计模式
    【设计模式
    【设计模式
    【设计模式
    【设计模式
  • 原文地址:https://www.cnblogs.com/ccdc/p/4431311.html
Copyright © 2011-2022 走看看