android 计时器(Handle+Runable 可重置时间
2018-11-02 本文已影响0人
CQ_TYL
// mhandle.postDelayed(timeRunable , 1000);调用 切勿重复调用
//currentSecond =0;重置时间
/*****************计时器*******************/
private Runnable timeRunable = new Runnable() {
@Override
public void run() {
currentSecond = currentSecond + 1000;
timerText.setText(TimeUtil.getFormatHMS(currentSecond));
if (!isPause) {
//递归调用本runable对象,实现每隔一秒一次执行任务
mhandle.postDelayed(this, 1000);
}
}
};
//计时器
private Handler mhandle = new Handler();
private boolean isPause = false;//是否暂停
private long currentSecond = 0;//当前毫秒数