CHRONOMETR is a simple timer, you can give it a start time, and take this timing, or if you don't give it a start time,
It will start with your time call. By default it will display the "minutes: Seconds" or "Mm:ss" in the current timer's worthwhile form,
Or you can use the set (string) timer value to an arbitrary string
Important attributes
Android:format defines the time format such as: HH:MM:SS
Important method
SetBase (long Base)//Set countdown timer setformat (String format)//Set display time format start ()//Start timer stop () Stop Timer//Call Setonchronometerticklistener when the timer changes (chronometer.onchronometerticklistene R 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:o nclick= "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> </LinearLayout>
java source
Package 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 chronometer = null; /** called when the activity is first created. */ @Override public 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 view) { chronometer.start (); } public void onstop (View view) { chronometer.stop (); } public Void onreset (View&nbsP;view) { Chronometer.setbase (Systemclock.elapsedrealtime ()); } }
The chronometer of Android control development