Android--countdowntimer Countdown Tool Class

Source: Internet
Author: User

The previous use of the countdown is written by their own, through the implementation of handler, only to find that the Android OS has implemented the tool class. Simple to use as follows. 1 import android.app.Activity;

2 ImportAndroid.os.Bundle;3 ImportAndroid.os.CountDownTimer;4 5  Public classCountdowntimeractivityextendsActivity {6     PrivateButton Mbtn_getcode;//User-selectable button-"Get Verification Code"7     PrivateCountdowntimer Mcountdowntimer;//countdown Tool class for sending verification codes8 9 @OverrideTen     protected voidonCreate (Bundle savedinstancestate) { One         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_countdowntimer); -Mbtn_getcode =Findviewbyid (r.id.btn_getcode); -         //Countdown Tool Class: Stop after 30 seconds with a 1-second interval theMcountdowntimer =NewCountdowntimer (30000, 1000) { -  - @Override -              Public voidOnTick (Longmillisuntilfinished) { +                 //millisuntilfinished will be from 30000,29000 ... until 0. -Btn_getprov.settext ("Resend (" + (millisuntilfinished/1000) + "s)"); +             } A  at @Override -              Public voidonfinish () { -                 //once the countdown is over, the user can click the button again--"Get Verification Code" -Btn_getprov.settext ("Get Verification Code"); -Btn_getprov.setenabled (true); -             } in         };
Turn on Countdown

Btn_getprov.setenabled (FALSE);
Mcountdowntimer.start ();

 -     }

Android--countdowntimer Countdown Tool Class

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.