Chronometer in milliseconds

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Chronometer in milliseconds

Postby Sword » Tue Aug 02, 2011 10:01 am

Hi all !
My problem is really annoying : I need a chronometer who Count up in milliseconds ! But I don't know how to do this ! :x

So, can you help me ?

Thanks in advance
Sword
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Aug 02, 2011 9:39 am
Location: France

Top

Re: Chronometer in milliseconds

Postby Dolenc » Mon Aug 22, 2011 5:07 pm

I know its old, but if you still havent found out( I just joined so its new to me :D).

You can use the Chronometer class that is in android.

You put a Chronometer element (if you want to see the seconds counting) on the layout.

In your activity you import

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.os.SystemClock;
  2. import android.widget.Chronometer;
  3.  
  4. //Add a variable
  5. private Chronometer crono;
  6.  
  7. //In onCreate method
  8. crono = (Chronometer) findViewById(R.id.chronoOnLayout);
  9.  
  10. //In onClick
  11. //StartButton (or wathever you use)
  12. crono.setBase(SystemClock.elapsedRealtime());
  13.                         crono.start();
  14. //Stop button
  15. crono.stop()
  16.  
  17. //Reset
  18. crono.setBase(SystemClock.elapsedRealtime());
  19.  
  20. //Function to get the time out
  21. public long giveMeTime(Chronometer crono) {
  22.                 long allMilli = SystemClock.elapsedRealtime() - crono.getBase();
  23.                
  24.                 return allMilli;
  25.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Thats basicly it.

Its all nicely coded here.
Dolenc
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Aug 22, 2011 4:51 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests