The chronometer of Android control development

Source: Internet
Author: User

(Transferred from: http://blog.csdn.net/sun6255028/article/details/6688349)

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

1 android:format    defines the time format such as: HH:MM:SS  

Important method

1 setbase (long Base)      // Set countdown timer   2 setformat (String format)    // Set the format   of the display time 3 start ()             // start timing   4 Stop ()              // Stop timer   5                                 // call  when timer changes 6

:

Routine Main.xml source code

1<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"2android:orientation= "Vertical"3Android:layout_width= "Wrap_content"4android:layout_height= "Wrap_content" >5   6<chronometer7Android:id= "@+id/chronometer"8Android:layout_width= "Wrap_content"9android:layout_height= "Wrap_content"/>Ten    One<LinearLayout AAndroid:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" > -        the<Button -android:onclick= "OnStart" -android:text= "Start timing" -Android:layout_width= "Wrap_content" +android:layout_height= "Wrap_content"/> -            +<Button Aandroid:onclick= "OnStop" atandroid:text= "Stop Timing" -Android:layout_width= "Wrap_content" -android:layout_height= "Wrap_content"/> -            -<Button -android:onclick= "OnReset" inandroid:text= "Reset" -Android:layout_width= "Wrap_content" toandroid:layout_height= "Wrap_content"/> +</LinearLayout> -</LinearLayout>

Java source Code

ackage Com.sx.Chronometer; Importandroid.app.Activity; ImportAndroid.os.Bundle; ImportAndroid.os.SystemClock; ImportAndroid.view.View; ImportAndroid.widget.Chronometer;  Public classChronometeractivityextendsActivity {PrivateChronometer chronometer =NULL; /**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                    Setcontentview (R.layout.main); Chronometer=(chronometer) Findviewbyid (r.id.chronometer); Chronometer.setformat ("Timing:%s"); }             Public voidOnStart (view view) {Chronometer.start (); }             Public voidonStop (view view) {chronometer.stop (); }             Public voidonreset (view view) {Chronometer.setbase (Systemclock.elapsedrealtime ()); }  }  

Android Control Development chronometer (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.