I am trying to display a countup timer with format 1.00 resolution. basically seconds and with hundredths of second or 10ms resolution. I have tried the chronometer function but still no luck, it seems it can only track 1 second resolution. here is some of my code:
public void stopwatch() {
stopWatch.setOnChronometerTickListener(new OnChronometerTickListener(){
@Override
public void onChronometerTick(Chronometer arg0) {
countUpmilli = (Long) ((SystemClock.elapsedRealtime() -arg0.getBase())/ 100);
countUpSec = (Long) ((SystemClock.elapsedRealtime() -arg0.getBase()) / 1000);
//asText = (countUp / 60) + ":" + (countUp % 60);
asText = (countUpSec / 1) + "." + (countUpmilli%100);
timertext.setText(asText);
}
});
stopWatch.start();
}
我认为您必须使用System.nanoTime();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.