当我从具有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;
}
}