Android 9th Lesson-Timer Chronometer

Source: Internet
Author: User

I studied clocks and timers today.

I think AnalogClock and DigitalClock can use it directly. The only thing you need to know is that AnalogClock can modify the dial and minute hand.

Methods are Android:dail and Android:hand_minute and Hand_hour.

The use of timers is described below.

First, just put a chronometer and a button in the XML. In order to click the Start button, start the timer, 20s stop.

 PackageCom.example.chronometer;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.SystemClock;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.Chronometer;ImportAndroid.widget.Chronometer.OnChronometerTickListener; Public classMainactivityextendsActivity {chronometer ch;    Button start; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); CH=(chronometer) Findviewbyid (r.id.test); Start=(Button) Findviewbyid (R.id.start); Start.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method Stub//Set Start timing timech.setbase (Systemclock.elapsedrealtime ()); //Start TimerCh.start (); Start.setenabled (false);        }            }); Ch.setonchronometerticklistener (NewOnchronometerticklistener () {@Override Public voidOnchronometertick (chronometer chronometer) {//TODO auto-generated Method Stub//if it's more than 20s from timing to now,                if(Systemclock.elapsedrealtime ()-ch.getbase () >20*1000) {ch.stop (); Start.setenabled (true);    }            }                    }); }    }

In order to achieve this function, we should implement this function by monitoring the buttons and timers.

I think it's possible to change the function to create a edittext, enter the timekeeping time, and then stop the timer ...

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.