Android Timer chronometer Use examples to explain _android

Source: Internet
Author: User
Tags set time string format

In Android, you can use timers to monitor time, the functionality of this class is to start the timer, stop timing, and then set the timer
mode, the following list of the Timer method prototype:
long getbase () ; // time to return to base,
String GetFormat () set by SetBase (long), Returns the current string format, which is a
void setbase (long base) implemented via SetFormat (); /Set time, value specified by the Count timer
void SetFormat (String format); To set the display, the timer will show the value of this parameter, if the string is
/null, the value returned is MM:SS
to describe an instance:

Package Com.example.android.apis.view;
Need The following import to get access to the app. since this//class is in a sub-package.

Import COM.EXAMPLE.ANDROID.APIS.R;
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 button;

    Mchronometer = (chronometer) Findviewbyid (r.id.chronometer);
    Watch for button clicks.
    Button = (button) Findviewbyid (R.id.start);
    Button.setonclicklistener (Mstartlistener)//corresponds to the start Timer button = (button) Findviewbyid (r.id.stop); Button.setonclicklistener (Mstoplistener); Corresponds to the Stop timer button = (button) Findviewbyid (r.id).Reset);
    Button.setonclicklistener (Mresetlistener);//corresponds to reset Number button = (button) Findviewbyid (R.id.set_format);
    Button.setonclicklistener (Msetformatlistener);//corresponds to the display format of the set time button = (button) Findviewbyid (R.id.clear_format); Button.setonclicklistener (Mclearformatlistener)//corresponds to the use of unformatted timing display features} View.onclicklistener Mstartlistener = new OnCli
    Cklistener () {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.set
    Format ("Formatted Time (%s)");

  }
  };
  View.onclicklistener Mclearformatlistener = new Onclicklistener () {  public void OnClick (View v) {mchronometer.setformat (null);
}
  };
 }

The above is the entire content of this article, I hope to learn to use the Android timer help, thank you for your reading.

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.