Implementation of the Countdown function in Android Development

Source: Internet
Author: User

The countdown is used in Android development. I checked some information, read the source code, write it out, and share it with you. If it is inappropriate, please correct it.

Write a class to inherit countdowntimer. As shown in the code below, rewrite the two methods to write what you want to do in the two methods. The code in onfinish () is to be done at the end; the Code in ontick (long m) is to be done at the beginning of the countdown, And the Parameter m is the time until the completion, in actual application, this parameter must have but cannot affect the application. In the constructor mycount (), the former is the number of time in the countdown, and the latter is the interval in the middle of every second, in milliseconds. For example, if the countdown is 30 seconds and the interval between two seconds is 1 second, two parameters can be written as mycount ).

 

Public class mycount extends countdowntimer {</P> <p> textview TT = (textview) findviewbyid (R. id. position); </P> <p> Public mycount (long millisinfuture, long countdowninterval) {<br/> super (millisinfuture, countdowninterval ); <br/>}</P> <p> @ override <br/> Public void onfinish () {<br/> TT. settext (""); </P> <p >}</P> <p> @ override <br/> Public void ontick (long millisuntilfinished) {<br/> TT. settext ("Please wait 60 seconds (" + millisuntilfinished/1000 + ")... "); <br/>}</P> <p>}

 

Instantiate a mycount in your code:

Mycount = new mycount );

 

Start countdown:

Mycount. Start ();

 

 

 

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.