0

Is there a way by which using the android chronometer class to set base of the chronometer in 15 minutes and from that period the times goes down until 0 seconds?

I have tried with setBase(60000) but this isn't work.

4

3 回答 3

2

一般来说,计时器的工作原理是这样的(如果您想将 Base 设置为特定的 nr):

mChronometer.setBase(SystemClock.elapsedRealtime() - (nr_of_min * 60000 + nr_of_sec * 1000)))

你问什么可以通过倒计时来完成(http://developer.android.com/reference/android/os/CountDownTimer.html

或者像这样使用计时器创建自己的倒计时(应该做更多的工作,因为我刚刚写了这个,还没有测试它)

private OnChronometerTickListener countUp = new OnChronometerTickListener(){
@Override
public void onChronometerTick(Chronometer chronometer){
            long elapsedTime = (SystemClock.elapsedRealtime() - mChronometerCountUp.getBase()) / 60000; 
            Log.v("counting up", elapsedTime); 
            // you will see the time counting up
            count_down--; 
                if(count_down == 0){
                mChronometerCountUp.stop();
            }
            // an int which will count down, 
            // this is not (very) accurate due to the fact that u r using the update part of the chronometer 
            // u just might implement the countdown i guess 
            // or 2 chronometers (one counting up and an other counting down using the elapsed time :p)
            // just remember programming is creating ur solution to problems u face its like expression urself
        };
    };
于 2013-05-28T06:58:20.437 回答
1

看看这个线程Android: chronometer as a persistent stopwatch。如何设置开始时间?什么是天文台“底座”?以及这个线程Android-Get time of chronometer 小部件。两者都没有直接回答你的问题,但那里的掘金应该引导你找到答案。

于 2013-02-09T12:45:14.653 回答
0

http://developer.android.com/reference/android/widget/Chronometer.html

要设置基本时间,您可以使用 elapsedRealtime(),您可以使用 setFormat() 输出格式

于 2013-02-09T12:49:45.433 回答