开发者

Chronometer set wrong long value

Set manually long value to chronometer.my long value is correct but when I set this to chronometer.setBase()it display specially character instead of correct time.

    // hourInt = 4
    // minInt = 34
    // secInt = 40
    Calendar cal1 = Calendar.getInstance();
                    cal1.set(Calendar.HOUR, hourInt);
                    cal1.set(Calendar.MINUTE, minInt);
                    cal1.set(Calendar.SECOND, secInt);

                long codeBase = cal1.getTime().getTime();
                System.out.println("Code Base..."+codeBase);
 chronometer.setBase(codeBase);
                chronometer.start();

it display special chraracter like开发者_如何学C 00:0) and 00:0* and all special character. how to set custom long value.


I was struggling with this myself until I managed to figure it out through trial and error.

Chronometer.setBase() wants millis based on the elapsed real time. This means that epoch milliseconds don't work. In order to be able to use epoch milliseconds, you have to call Chronometer.setBase() like this:

chronometer.setBase(SystemClock.elapsedRealtime() -
    System.currentTimeMillis() + codeBase);

The math effectively converts the epoch milliseconds to elapsed real time milliseconds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜