Chronometr is a simple timer, you can give it a start time, and this timer, or if you don't give it a start time,
It will start with your time call. By default, it will be displayed in the form of "minute: Second" or "mm: SS" in the current timer ",
Or you can use the Set (string) timer value to any string
Important attributes
Android: format defines the time format, for example, HH: mm: Ss.
Important Methods
Setbase (long base) // set the countdown timer setformat (string format) // set the display time format start () // start timing stop () // stop the timer // call setonchronometerticklistener (chronometer. onchronometerticklistener listener)
Routine main. xml source code
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> <chronometer Android: id = "@ + ID/chronometer" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> <linearlayout Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> <button Android: onclick = "onstart" Android: text = "start timing" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> <button Android: onclick = "onstop" Android: text = "Stop timing" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> <button Android: onclick = "onreset" Android: text = "reset" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> </linearlayout>
Java source code
Ackage COM. SX. chronometer; import android. app. activity; import android. OS. bundle; import android. OS. systemclock; import android. view. view; import android. widget. chronometer; public class chronometeractivity extends activity {private chronometer = NULL;/** called when the activity is first created. * // @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); chronometer = (chronometer) findviewbyid (R. id. chronometer); chronometer. setformat ("Timing: % s");} public void onstart (view) {chronometer. start ();} public void onstop (view) {chronometer. stop ();} public void onreset (view) {chronometer. setbase (systemclock. elapsedrealtime ());}}