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