Android:数分钟内的Chronometer SetBase [英] Android: Chronometer SetBase in minutes

查看:266
本文介绍了Android:数分钟内的Chronometer SetBase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用android chronometer类在15分钟内设置秒表的基数,并且从那段时间开始计时直到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?

我尝试使用setBase(60000),但这不起作用.

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

推荐答案

通常,天文钟的工作原理如下(如果您想将Base设置为特定的nr):

In general the chronometer works like this (if you would like to set the Base to a specific nr):

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

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

您要问的事情可以通过倒计时完成( http://developer .android.com/reference/android/os/CountDownTimer.html )

what you are asking can be done through a countdown (http://developer.android.com/reference/android/os/CountDownTimer.html)

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

Or create your own countdown by using the chronometer like this (more work should be done cause i just wrote this and did not test it yet)

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

这篇关于Android:数分钟内的Chronometer SetBase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆