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("重新获取"); } } }