2

我正在使用计时器在我的 android 应用程序中显示时间。

我想获取屏幕上显示的计时器值。我试着用

int stoppedMilliseconds = 0;
          String chronoText = chronometer.getText().toString();
          String array[] = chronoText.split(":");
          if (array.length == 2) {
            stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 1000
                + Integer.parseInt(array[1]) * 1000;
          } else if (array.length == 3) {
            stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 60 * 1000 
                + Integer.parseInt(array[1]) * 60 * 1000
                + Integer.parseInt(array[2]) * 1000;
          }
          chronometer.setBase(SystemClock.elapsedRealtime() - stoppedMilliseconds);

并获得我使用的价值long elapsedMillis = SystemClock.elapsedRealtime() - chronometer.getBase();

它对我来说显示了一个特定的数字,它看起来不像屏幕上显示的时间。如果屏幕上的计时器显示 1 秒,我想得到精确的 1 秒而不是任何随机数。

有没有人可以帮我解决这个问题?

4

0 回答 0