The chronometer of Android control development

Source: Internet
Author: User

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

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.