Android
android.widget
public class

android.widget.Chronometer

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.widget.TextView ViewTreeObserver.OnPreDrawListener
android.widget.Chronometer

Class that implements a simple timer.

You can give it a start time in the elapsedRealtime() timebase, and it counts up from that, or if you don't give it a base time, it will use the time at which you call start(). By default it will display the current timer value in the form "MM:SS" or "H:MM:SS", or you can use setFormat(String) to format the timer value into an arbitrary string.

Summary

XML Attributes

Attribute name Related methods  
android:format   Format string: if specified, the Chronometer will display this string, with the first "%s" replaced by the current timer value in "MM:SS" or "H:MM:SS" form. 
XML Attributes inherited from class android.widget.TextView
XML Attributes inherited from class android.view.View
Constants inherited from class android.view.View
Fields inherited from class android.view.View

Public Constructors

            Chronometer(Context context)
Initialize this Chronometer object.
            Chronometer(Context context, AttributeSet attrs)
Initialize with standard view layout information.
            Chronometer(Context context, AttributeSet attrs, int defStyle)
Initialize with standard view layout information and style.

Public Methods

          long  getBase()
Return the base time as set through setBase(long).
          String  getFormat()
Returns the current format string as set through setFormat(String).
          void  setBase(long base)
Set the time that the count-up timer is in reference to.
          void  setFormat(String format)
Sets the format string used for display.
          void  start()
Start counting up.
          void  stop()
Stop counting up.

Protected Methods

          void  onDetachedFromWindow()
This is called when the view is detached from a window.
          void  onWindowVisibilityChanged(int visibility)
Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE).
Methods inherited from class android.widget.TextView
Methods inherited from class android.view.View
Methods inherited from class java.lang.Object
Methods inherited from interface android.graphics.drawable.Drawable.Callback
Methods inherited from interface android.view.KeyEvent.Callback
Methods inherited from interface android.view.ViewTreeObserver.OnPreDrawListener

Details

XML Attributes

android:format

Format string: if specified, the Chronometer will display this string, with the first "%s" replaced by the current timer value in "MM:SS" or "H:MM:SS" form. If no format string is specified, the Chronometer will simply display "MM:SS" or "H:MM:SS".

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol format.

Related Methods

Public Constructors

public Chronometer(Context context)

Initialize this Chronometer object. Sets the base to the current time.

public Chronometer(Context context, AttributeSet attrs)

Initialize with standard view layout information. Sets the base to the current time.

public Chronometer(Context context, AttributeSet attrs, int defStyle)

Initialize with standard view layout information and style. Sets the base to the current time.

Public Methods

public long getBase()

Return the base time as set through setBase(long).

public String getFormat()

Returns the current format string as set through setFormat(String).

public void setBase(long base)

Set the time that the count-up timer is in reference to.

Parameters

base Use the elapsedRealtime() time base.

public void setFormat(String format)

Sets the format string used for display. The Chronometer will display this string, with the first "%s" replaced by the current timer value in "MM:SS" or "H:MM:SS" form. If the format string is null, or if you never call setFormat(), the Chronometer will simply display the timer value in "MM:SS" or "H:MM:SS" form.

Parameters

format the format string.

public void start()

Start counting up. This does not affect the base as set from setBase(long), just the view display. Chronometer works by regularly scheduling messages to the handler, even when the Widget is not visible. To make sure resource leaks do not occur, the user should make sure that each start() call has a reciprocal call to stop().

public void stop()

Stop counting up. This does not affect the base as set from setBase(long), just the view display. This stops the messages to the handler, effectively releasing resources that would be held as the chronometer is running, via start().

Protected Methods

protected void onDetachedFromWindow()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

protected void onWindowVisibilityChanged(int visibility)

Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE). Note that this tells you whether or not your window is being made visible to the window manager; this does not tell you whether or not your window is obscured by other windows on the screen, even if it is itself visible.

Parameters

visibility The new visibility of the window.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56