天文台复位天文台

2023-09-06 02:40:39 作者:﹏祗剩寂寞ゞ

我试图完全重新启动天文台及其不起作用。相反,它被暂停。基本上,我试图做的是做一些事情,而天文台表计数,直到10的完成,我们提示用户再次尝试之后。在这种情况下,我们要重复的计数从1到10秒。但天文台开始0开始从暂停的时间,而不是。

I am trying to completely restart Chronometer and its does not work. Instead it is being paused. Basically what I am trying to do is to do something while chronometer is counting till 10. After its done we prompt the user to try again. In which case we want to redo the count from 1 to 10 sec. But the Chronometer starts from the paused time instead of starting 0.

这里是code:

_cutOfTime = 10; // constant

每一次按键pressed做的startRecording()

应该总是启动记时计,而不是停止/暂停,但它的作用相反

it should always initiate the Chronometer instead of stop/pause it, but it does the opposite

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();
}

有没有一种方法可以重设时计,因此不会暂停,但完全停止?

Is there a way to reset the chronometer so it does not pause but completely stop?

推荐答案

当我打的时计一段时间回来我只是用setBase()方法之前调用start到基地到当前时间设置()。根据您的具体需求,你可能需要添加一些逻辑,围绕是否在开始之前重置天文台与否。

When I played with the chronometer awhile back I just used the setBase() method to set the base to the current time just before calling start(). Depending on your exact needs you may need to add some logic around whether to reset the chronometer or not before starting it.

View.OnClickListener mStartButtonListener = new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            mChronometer.setBase(SystemClock.elapsedRealtime());
            mChronometer.start();
        }
    };
相关推荐