Usage of the timer (Chronometer) and the timer chronometer
Android provides a timer component: Chronometer, Which is extends TextView. Therefore, a piece of text is displayed, but the display time is from the start time, it only provides the android: format attribute for specifying the counting format of the timer.
Chronomet
Android --- 25 --- Chronometer timer, android TimerChronometer TimerIt provides an android: format attribute to specify the timer format.SetBase (long base): Set the start timeSetFormat (String format): Set the display time formatStart (): start timingStop (): stop timing
SetOnchronometerTickListener (): binds the time listener to the timer. This listener is triggered when the timer changes.
The time is 20 s. When the time is reached, the time is sto
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 (strin
The android SDK provides multiple time services. These time services mainly process tasks that occur at a certain interval or a certain time in the future. In the Android system, the time service scope can be either the application itself or the entire android system. This section describes how to use these time services and provides a large number of instances for readers to learn.
Timer: chronometer
The project directory of the sample code in this s
In the Android SDK, a timer is provided for us. This timer is called Chronometer. We can use it as a component of Android, and it also has its own unique method. The following is an example of how to use the timer and common methods.
Like other UI components, when we want to use it, the corresponding position in the layout file declares the location and attribute of the timer.
Copy codeThe Code is as follows: Android: id = "@ + id/
This article shows you how to use the Chronometer control to implement an instance of an Android timer.
Put the final implementation diagram first:
The idea of Android timer implementation
Use the chronometer control to implement the action of the meter. Set the initial time by setting SetBase (long base) and add a setonchronometerticklistener to it (Chronometer.onchronometerticklistener L) Event to de
Timers chronometer and Clocks (AnalogClock and DigitalClock)(1) Android provides two clock components: AnalogClock and Digitalclock,digitalclock inherit the TextView component, which means that it is a text box, but the content is always the current time, Therefore, setting the Android:text property for DigitalClock does not work; AnalogClock inherits the view component and overrides the view's OnDraw method, which draws the analog clock on the view.(
Company's previous project, see Using this Android with the countdown control chronometer, now integrates
First look at the effect:
Method Introduction:
long getbase ();//return base time, set by SetBase (long), can be a systemclock.elapsedrealtime () String GetFormat ()//returns the current string format, which is a void setbase (long base) implemented via SetFormat ();//Set time, value of the count timer specified void Set
In the Android SDK, we have a timer, called chronometer, that we can become a component of Android, and it has its own unique approach. Here are some examples of how this timer is used and how it is used.As with other UI components, when we want to use it, we declare the position and attributes of the timer in the corresponding position in the layout file.
Copy Code code as follows:
Android:id= "@+id/
This example for you to share the Android Chronometer timer Basic use method, for your reference, the specific content as follows
By default, the Chronometer component outputs only the MM:SS or H:MM:SS time format. For example, when the timer is 1 minutes 20 seconds, the Chronometer component displays 01:20. If you want to change the content of the displayed inf
CHRONOMETR is a simple timer, you can give it a start time, and take this timing, or if you don't give it a start time, It will start with your time call. By default it will display the "minutes: Seconds" or "Mm:ss" in the current timer's worthwhile form, Or you can use the set (string) timer value to an arbitrary string Important attributes Android:format defines the time format such as: HH:MM:SS Important method SetBase (long Base)//Set countdown timer setformat (String format)//Set display t
; CalendarViewAndroid:id= "@+id/calendarview"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:firstdayofweek= "3"Android:shownweekcount= "4" />Relativelayout>Modify the code inside the mainactivity, load the above defined layout file, and then run the program, you can see the interface effect shown.Second, chronometerThe chronometer is a simple timer that can be used by setbase () to give it a base time and count fr
/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > CalendarViewAndroid:id= "@+id/calendarview"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:firstdayofweek= "3"Android:shownweekcount= "4" />Relativelayout>Modify the code inside the mainactivity, load the above defined layout file, and then run the program, you can see the interface effect shown.Second, chronometerThe chronometer i
Chronometer directly inherits the TextView component, which displays a piece of text that shows how long it has been since some time. We look at the source of chronometer:It can be seen that the timer is directly inherited TextView, of course, can use all the properties and methods of TextView. At the same time it also has its own internal interface OnchronometerticklistenerNew properties and methods for timers:The usual methods for timers are as fol
Timers to calculate the time spent by each athlete, and in the Android system, this chronograph function can be used with the chronometer component, the inheritance structure of this class is as follows:2Java.lang.Object?Android.view.View?Android.widget.TextView?Android.widget.Chronometera common approach
1
public Chr Onometer (Context context)
construct
Create chronometer
Preface
This chapter describes android. widget. Chronometer. OnChronometerTickListener and its version is Android 2.2 r1. I look forward to your participation in Android Chinese API translation, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog Garden: http://www.cnblogs.com/
Android Chinese translation group: http://www.cnblogs.com/over140/
Body
I. Structure
Public stat
The project needs to implement a timing function, although the use of chronometer can be very convenient to achieve the timing function, but need a countdown control.
Baidu has a number of methods, the countdown is not, so with chronometer encapsulated a countdown class, the spirit of open source, to share to everyone!
Nonsense don't say that go into the subject
First, the XML layout is as follows:
First define the Activity_main.xml fileThe code is as follows:Then rewrite the Mainactivity classThe code is as follows:Package Com.example.myclock;import Android.os.bundle;import Android.os.systemclock;import android.os.Vibrator; Import Android.app.activity;import android.app.service;import Android.view.menu;import Android.view.View;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.chronometer;import Android.widget.chronometer.onchronometerticklistener;
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.