zoukankan      html  css  js  c++  java
  • android timer倒计时

    private Handler mHandler = new Handler() {
            public void handleMessage(Message msg) {
                int arg1 = msg.arg1;
                if (arg1 == 0) {//时间到
                    
                }
                textView.setText(String.valueOf(arg1));
            }
        };
     
        /**
         * 开始自动减时
         */
        private void startTime() {
            if (timer == null) {
                timer = new Timer();
            }
     
            timerTask = new TimerTask() {
     
                @Override
                public void run() {
     
                    Message message = Message.obtain();
                    message.arg1 = time;
                    mHandler.sendMessage(message);//发送消息
     
                    time--;//自动减1
     
                }
            };
            timer.schedule(timerTask, 0, 1000);//1000ms执行一次
        }
     
    private void stopTime() { if (timer != null) { timer.cancel(); timer = null; } if (timerTask != null) { timerTask.cancel(); timerTask = null; } time = 0; }

     

  • 相关阅读:
    开启Spring Boot 之旅
    Java笔试面试练习题---集合
    Python
    Python
    Redis -下载与基本使用
    Git
    Vue全家桶-Vue-router&Vuex
    Es6
    Vue-前端
    Django基础及实战
  • 原文地址:https://www.cnblogs.com/IT-lss/p/10108709.html
Copyright © 2011-2022 走看看