5

当我使用该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;
    }
}
4

0 回答 0