Android Timer chronometer-android Learning Tour (21)

Source: Internet
Author: User

chronometer Introduction

Chronometer and Digitalcolok both inherit and TextView, but chronometer is not the current time to display, but rather how much time has elapsed since the beginning of a certain time.

Properties of the Chronometer

20-Second Memory instance
 PackagePeng.liu.testview;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.SystemClock;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.Chronometer; Public  class mainactivity extends Activity {    PrivateButton Strat;PrivateChronometer chronometer;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        Chronometer = (chronometer) Findviewbyid (r.id.chronometer);        Strat = (Button) Findviewbyid (R.id.start); Strat.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View view)                {Chronometer.setbase (Systemclock.elapsedrealtime ());                Chronometer.start (); Strat.setenabled (false);        }        }); Chronometer.setonchronometerticklistener (NewChronometer.onchronometerticklistener () {@Override             Public void Onchronometertick(chronometer chronometer) {if(Systemclock.elapsedrealtime ()-chronometer.getbase () > -* +) {chronometer.stop (); Strat.setenabled (true);    }            }        }); }}
<LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android"    Xmlns:tools="Http://schemas.android.com/tools" Android:layout_width="Match_parent"    Android:layout_height="Match_parent" Android:paddingleft="@dimen/activity_horizontal_margin"    Android:paddingright="@dimen/activity_horizontal_margin"    Android:paddingtop="@dimen/activity_vertical_margin"    Android:paddingbottom="@dimen/activity_vertical_margin"    Tools:context=". Mainactivity "    android:orientation="Vertical">  <chronometerandroid:layout_width="Wrap_content"android:layout_height ="Wrap_content"android:id="@+id/chronometer"/>                      <buttonandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" android:id="@+id/start"android:text="Start"/>                                </linearlayout>

Android Timer chronometer-android Learning Tour (21)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.