Usage of chronometer-start timing, stop timing, re-timing, set the time mode

Source: Internet
Author: User

For more information, see:

Android timer chronometer basic use: http://bbs.chinaunix.net/archiver? Tid-1329164.html

 

Chistmmeter. xml:

<? XML version = "1.0" encoding = "UTF-8"?>

<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"

Android: Orientation = "vertical"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

>

 

<Chronometer Android: text = "chronometer"

Android: Id = "@ + ID/chronometer"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"/>

<Button Android: text = "start"

Android: Id = "@ + ID/start"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"/>

<Button Android: text = "stop"

Android: Id = "@ + ID/stop"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"/>

<Button Android: text = "reset"

Android: Id = "@ + ID/RESET"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"/>

<Button Android: text = "set_format"

Android: Id = "@ + ID/set_format"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"/>

<Button Android: text = "clear_format"

Android: Id = "@ + ID/clear_format"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"/>

</Linearlayout>

------------------------------------------------------------------------------------------------------------ Chronometerdemo. java: Package COM. example. android. APIS. view; import android. app. activity; import android. OS. bundle; import android. OS. systemclock; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. chronometer; public class chronometerdemo extends activity {chronometer mchronometer; @ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. chronometer); button; mchronometer = (chronometer) findviewbyid (R. id. chronometer); // watch for button clicks. button = (button) findviewbyid (R. id. start); button. setonclicklistener (mstartlistener); // corresponding to start timing button = (button) findviewbyid (R. id. stop); button. setonclicklistener (mstoplistener); // corresponding to the stop timing button = (button) findviewbyid (R. id. reset); button. setonclicklistener (mresetlistener); // corresponding to the reset number button = (button) findviewbyid (R. id. set_format); button. setonclicklistener (msetformatlistener); // The display format of the set time is button = (button) findviewbyid (R. id. clear_format); button. setonclicklistener (mclearformatlistener); // This parameter corresponds to a non-formatted timing display function.} view. onclicklistener mstartlistener = new onclicklistener () {public void onclick (view v) {mchronometer. start () ;}}; view. onclicklistener mstoplistener = new onclicklistener () {public void onclick (view v) {mchronometer. stop () ;}}; view. onclicklistener mresetlistener = new onclicklistener () {public void onclick (view v) {mchronometer. setbase (systemclock. elapsedrealtime () ;}}; view. onclicklistener msetformatlistener = new onclicklistener () {public void onclick (view v) {mchronometer. setformat ("formatted time (% s)") ;}}; view. onclicklistener mclearformatlistener = new onclicklistener () {public void onclick (view v) {mchronometer. setformat (null );}};}

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.