Short answer. Change your building of 'asText' to:
String asText = (countUp / 60) + ":" + (String.format("%02d",
(countUp % 60)) + "." + (String.format("%03d", (countUp_milli %
1000)));
Long answer. Since this code will be called a *lot*, it would be good
to profile it. The compiler should convert the code above to use a
StringBuilder and a bunch of append() calls. But a new StringBuilder
will still get instantiated, populated, and then discarded on each
invocation of onChronometerTick. It might be worthwhile to declare a
single StringBuilder in your class and (re)use it on every call.
On Sep 29, 12:16 am, Hassy <[email protected]> wrote:
> I'm trying to create a countup timer with milliseconds.
> I used Chronometer but I don't know how to display milliseconds.
>
> Chronometer crono = (Chronometer) findViewById(R.id.chrono);
> startTime = SystemClock.elapsedRealtime();
> crono.setOnChronometerTickListener(new
> OnChronometerTickListener() {
> public void onChronometerTick(Chronometer arg0) {
> countUp = (SystemClock.elapsedRealtime() -
> arg0.getBase()) / 1000;
> countUp_milli = (SystemClock.elapsedRealtime() -
> arg0.getBase());
> String asText = (countUp / 60) + ":" + (countUp %
> 60);
> timeflg.setText(asText);
> }
>
> });
>
> crono.start();
>
> please tell me how to display milliseconds.
>
> Thank you
>
> Hassy
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en