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 ();