简介:
暂停,再次开始会延续之前的计时.
布局:
<Chronometer/>
代码:
private boolean isChronometerStart;
private long mRangeTime;
暂停:
mChronometer.stop();
mRangeTime=SystemClock.elapsedRealtime();
开始:
if(mRangeTime!=0) {
mChronometer.setBase(mChronometer.getBase() + (SystemClock.elapsedRealtime() -mRangeTime));}
else{
mChronometer.setBase(SystemClock.elapsedRealtime());}
mChronometer.start();
设置时间格式为00:00:00:
inthour= (int) ((SystemClock.elapsedRealtime() -mChronometer.getBase()) /1000/60);
mChronometer.setFormat("0"+String.valueOf(hour) +":%s");