Android的天文台启动和停止,但停止时进行计数 [英] Android Chronometer starts and stops but carries on counting when stopped
问题描述
我已经创建了一个有一个切换按钮来启动和停止天文台表,就像秒表一样的应用程序。当你第一次preSS切换按钮(执行时。开始()
),记时计将开始计时,当你再preSS一次按钮(执行时 .stop()
),记时计在屏幕上出现停止计数,因为它应该,但是当它然后重新启动它表明,它实际上仍是在后台计算并显示时间在屏幕上,就好像从来没有停止过搜索结果
code:结果
tglStartStop.setOnCheckedChangeListener(新OnCheckedChangeListener(){ @覆盖
公共无效onCheckedChanged(CompoundButton buttonView,
布尔器isChecked){ 如果(tglStartStop.isChecked()){ chronStopwatch.start();
} 其他{ chronStopwatch.stop();
} } });
添加此行之前(chronStopwatch.start();):
chronStopwatch.setBase(SystemClock.elapsedRealtime());
I've created an app that has a toggle button to start and stop a Chronometer, like a stop watch. When you first press the toggle button (executes .start()
), the chronometer will start counting, when you then press the button again (executes .stop()
), the chronometer appears on screen to stop counting as it should but when it is then started again it shows that it's actually still been counting in the background and shows the time on screen as if it was never stopped
code:
tglStartStop.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (tglStartStop.isChecked()) {
chronStopwatch.start();
}
else {
chronStopwatch.stop();
}
}
});
Add this line before (chronStopwatch.start();):
chronStopwatch.setBase(SystemClock.elapsedRealtime());
这篇关于Android的天文台启动和停止,但停止时进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!