使用介绍
TimerCount timer = new TimerCount(60000, 1000, code);
timer.start();
工具类代码
import android.os.CountDownTimer;
import android.widget.Button;import com.xinli.wenet.base.MyApplication;
import com.xinli.wenet.R; /**
* The type Timer count.
*/
public class TimerCount extends CountDownTimer {
private Button bnt; /**
* Instantiates a new Timer count.
*
* @param millisInFuture the millis in future
* @param countDownInterval the count down interval
* @param bnt the bnt
*/
public TimerCount(long millisInFuture, long countDownInterval, Button bnt) {
super(millisInFuture, countDownInterval);
this.bnt = bnt;
} /**
* Instantiates a new Timer count.
*
* @param millisInFuture the millis in future
* @param countDownInterval the count down interval
*/
public TimerCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
} @Override
public void onFinish() { bnt.setClickable(true);
bnt.setTextColor(MyApplication.getAppContext().getResources().getColor(R.color.colorBlue));
bnt.setText("获取动态码"); }
@Override
public void onTick(long arg0) {
// TODO Auto-generated method stub
bnt.setClickable(false);
bnt.setText(arg0 / 1000 + "秒后重新获取");
bnt.setTextColor(MyApplication.getAppContext().getResources().getColor(R.color.colorLine));
}
}