无法启动计时器或无法正常工作

时间:2013-07-03 07:12:06

标签: android timer chronometer

当我从具有start()功能的另一个类启动计时器时。它似乎没有开始。它总是给我起始值"00:00",仅此而已。

 public class Kronometre {
    Context context;
    long countUp;
    Chronometer stopWatch;
    String asText = "00.00";

    public Kronometre(Context context) {
        this.context = context;
        stopWatch = new Chronometer(context);
    }

    public void start() {
        stopWatch.setOnChronometerTickListener(new OnChronometerTickListener(){
            @Override
            public void onChronometerTick(Chronometer arg0) {
                countUp = (SystemClock.elapsedRealtime() - arg0.getBase()) / 1000;
                asText = (countUp / 60) + "." + (countUp % 60);
            }
        });
        stopWatch.start();
    }

    public String getTime() {
        return asText;
    }
}

0 个答案:

没有答案