Company's previous project, see Using this Android with the countdown control chronometer, now integrates
First look at the effect:
<chronometer
android:id= "@+id/chronometer"
android:layout_width= "wrap_content"
android:layout_ height= "30DP"/>
<button
android:onclick= "Start"
android:text= "starting"
android:layout_width= " Wrap_content "
android:layout_height=" wrap_content "/>
<button android:onclick=
" Stop "
android:text= "Stop"
android:layout_width= "wrap_content"
android:layout_height= "Wrap_content"/>
<button
android:onclick= "reset"
android:text= "reset"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"/>
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 SetFormat (string format) //Set What is displayed, the timer will show the value of this argument, and if the string is null, the value returned is the MM:SS format
Private chronometer chronometer;
The total time recorded by private long recordtime;//
@Override
protected void onCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_main);
Chronometer= (chronometer) Findviewbyid (r.id.chronometer);
Chronometer.setformat ("Timing:%s");//Setting the format displayed
toast.maketext (mainactivity.this, "" +recordtime, Toast.length_short ). Show ();
public void Start (view view) {
chronometer.setbase (systemclock.elapsedrealtime ()-recordtime);//Skip the time that has been recorded
Chronometer.start ();
}
public void Stop (view view) {
chronometer.stop ();
Recordtime=systemclock.elapsedrealtime ()-chronometer.getbase ()//time to save this record
} public
void Reset (View View) {
recordtime=0;//reset time
chronometer.setbase (Systemclock.elapsedrealtime ());
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.