• 显示倒计时的Button按钮


    package com.pingyijinren.helloworld.activity;
    
    import android.os.CountDownTimer;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import com.pingyijinren.helloworld.R;
    
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
        private Button button;
        private TimeCount timeCount;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            button = (Button) findViewById(R.id.button);
            button.setOnClickListener(this);
    
            timeCount=new TimeCount(60000,1000);
        }
    
        @Override
        public void onClick(View v) {
            timeCount.start();
        }
    
        private class TimeCount extends CountDownTimer {
            /**
             * @param millisInFuture    The number of millis in the future from the call
             *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
             *                          is called.
             * @param countDownInterval The interval along the way to receive
             *                          {@link #onTick(long)} callbacks.
             */
            public TimeCount(long millisInFuture, long countDownInterval) {
                super(millisInFuture, countDownInterval);
            }
    
            @Override
            public void onTick(long millisUntilFinished) {
                button.setEnabled(false);
                button.setText(millisUntilFinished/1000+"秒");
            }
    
            @Override
            public void onFinish() {
                button.setEnabled(true);
                button.setText("重新获取");
            }
        }
    }
  • 相关阅读:
    Python语言解析xml文件
    运行manage.py db shell出错
    ImportError: No module named win32com.client
    ImportError: No module named urllib2
    《演讲之禅》 读书笔记
    no such table: django_admin_log
    2 策略模式(2)
    1 简单工厂模式
    2 策略模式(1)
    无言
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5553755.html
Copyright © 2020-2023  润新知