Development of Android controls-chronometer

Source: Internet
Author: User

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 ());}}


Related Article

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.