Android Countdown Tool Class

Source: Internet
Author: User

In peacetime when we program, often use the countdown to this function, many people do not know that Android has helped encapsulate a class, often write their own. Now that this class has been discovered, let's share it:


The remaining time is constantly shown in a TextView code as follows:

[Java]View Plaincopy
  1. Private  TextView Vertifyview;
  2. PrivateCountdowntimer timer =NewCountdowntimer (10000,  +) {  
  3.   
  4.          @Override   
  5.          public   void  ontick ( long  millisuntilfinished)  {  
  6.              Vertifyview.settext (Millisuntilfinished / 1000 " can be re-sent after seconds "
  7. }
  8.          @Override   
  9.         public   void  onfinish ()  {  
  10.              vertifyview.setenabled (true );   
  11.              Vertifyview.settext (" Get Verification Code " );   
  12. }
  13. };

The call is simple: Timer.start ();

The final explanation: Countdowntimer timer = new Countdowntimer (10000, 1000), the first parameter represents the total time, and the second parameter represents the time interval. This means that the method Ontick is called back every second, and then the OnFinish method is recalled after 10 seconds.

Android 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.