有没有办法使用安卓计时器类在15分钟内设置计时器的基础,从那个时间开始,时间会下降到0秒?
我尝试使用setBase(60000)
,但这不起作用。
答案 0 :(得分: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
};
};
答案 1 :(得分:1)
查看此帖子Android: chronometer as a persistent stopwatch. How to set starting time? What is Chronometer "Base"?以及此帖子Android - Get time of chronometer widget。既没有直接回答你的问题,但那里的掘金应该引导你回答。
答案 2 :(得分:0)
http://developer.android.com/reference/android/widget/Chronometer.html
设置基准时间可以使用elapsedRealtime(),并且可以使用setFormat()输出格式