我正在尝试完全重新启动 Chronometer,但它不起作用。相反,它正在暂停。基本上我想做的是在计时器计数到 10 时做一些事情。完成后,我们会提示用户再试一次。在这种情况下,我们希望将计数从 1 秒重新计算到 10 秒。但是 Chronometer 从暂停时间开始,而不是从 0 开始。
这是代码:
_cutOfTime = 10; // constant
每次按下按钮时startRecording()
它应该始终启动 Chronometer 而不是停止/暂停它,但它却相反
protected void startRecording(){
this._watch = (Chronometer) findViewById(R.id.chrono);
if (this._watch != null)
this._watch.setOnChronometerTickListener(new OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
long countUp = (SystemClock.elapsedRealtime() - chronometer.getBase()) / 1000;
Log.i(_tag, "time now: " + String.valueOf(countUp));
if(countUp > _cutOfTime)
{
Log.i(_tag, "stop recording!!: ");
_watch.stop();
stopRecordWav();
launchPromptWithResults();
}
long sec = countUp % 60;
String asText = "" + sec;
_textView.setText("Recorded: " + asText);
}
});
if (_watch != null)
_watch.start();
}
有没有办法重置计时器,使其不会暂停而是完全停止?