Chronometer Android Timer component chronometer use, Android Talk time long timing control

Source: Internet
Author: User

The use of counters is often required during Android development, and we can use handler to achieve interval operation.

For example, press two to return back to exit, repeat the page every few seconds, and so on.

However, there are often a class of requirements that are recorded as long as they are called.

This is used in the Android Android.widget package under the chronometer this component.


Reprint Please specify: Thank you


chronometer Introduction

Class that implements a simple timer.
* <p>
* Can give it a start time in the {@link systemclock#elapsedrealtime} timebase,
* And it counts up from that, or if you don ' t give it a base time, it'll use the
* Time at which @link #start}. By default it would display the current
* Timer value in the form "Mm:ss" or "h:mm:ss", or can be use {@link #setFormat}
* To format the timer value into an arbitrary string.
*
* @attr ref Android. R.styleable#chronometer_format



My English is not good, it is not in this caught dead. I'm sorry.....



First look at the layout file



three buttons and one chronometer control does not have a special method



Activity Logic Code Section


Most of the methods have been commented

Note that the Chronometer.gettext () method returns the Charsequence object, which allows us to manipulate the data inside

The methods inside the Charsequence class are:

public int length ();

public char charAt (int index);

Public charsequence subsequence (int start, int end);

Public String toString ();

These four methods look at the name also know what the meaning of the first gets the length, the second based on the position to get the character, the third Intercept, the fourth ToString


We can do different things based on the attributes we get, such as: to 5 seconds, you can

if ("00:05". Equals (Text.tostring ())) {

The operation to be performed;

}


You can also get the characters

if (Text.charat (Text.length ()-1) ==5) {

The operation to be performed;

}


You can also split the string by itself. In short, various methods are not caught dead.



This is the use of a simple timer in Android development.




Chronometer Android Timer component chronometer use, Android Talk time long timing control

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.