Android_Chronometer暂停Android_Chronometer

2023-09-03 22:57:55 作者:〆、赞、我们旳爱 ≥

我想暂停计时表后,我点击我要继续chromoneter计数按钮...我搜索,但不能与功能这...怎么办呢?

I want to pause chronometer and after I click the button I want to continue chromoneter to count... I search but couldn't a function related this.. how can do it?

推荐答案

您是要去需要,保持跟踪已经过去了,因为该天文台开始的时间变量:

You are gonna need a variable that keeps track on the time that has passed since the Chronometer was started:

long timeWhenStopped = 0;

当你停止计时表这样的更新变量的值:

Update the value of the variable when you stop the chronometer like this:

timeWhenStopped = mChronometer.getBase() - SystemClock.elapsedRealtime();
mChronometer.stop();

我们也将使用这个变量开始前调整记时计:

We will also use this variable to adjust the chronometer before starting it:

mChronometer.setBase(SystemClock.elapsedRealtime() + timeWhenStopped);
mChronometer.start();

最后,如果你有办法重置您的天文台表,那么你应该记得也重置timeWhenStopped变量。事情是这样的:

And finally if you have a way to reset your chronometer then you should remember to also reset the timeWhenStopped variable. Something like this:

mChronometer.setBase(SystemClock.elapsedRealtime());
timeWhenStopped = 0;
相关推荐
 
精彩推荐
图片推荐