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.