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

  • 相关阅读:
    Spring 事务XML配置
    启用事务注解
    ebay 店铺状态
    lambda Map Reduce
    sublime3注册码
    使用多线程
    Spring AOP学习(六)
    添加依赖库
    CodeForces 867B Save the problem
    POJ 3264 Balanced Lineup (线段树查找最大最小值)
  • 原文地址:https://www.cnblogs.com/ccdc/p/4431311.html
Copyright © 2011-2022 走看看