------You need to work hard, you are not qualified to rest-----
Anroid in the countdown implementation:
In this first described the younger brother understand, and then add the finishing. Excuse me
1. Timer and TimerTask
public class TimerTask extends Activity { //Set a countdown private int Reclen =12; Private TextView TextView; Timer timer=new timer (); public void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.timertask); textview= (TextView) Findviewbyid (r.id.txttime); After a delay of 1000 milliseconds to start execution, the second 1000 is how long the interval executes timer.schedule (task,1000,1000);//timertask } timertask task= New TimerTask () {public void run () { ///jump to the main thread with the runonuithread (newly Runnable () {//ui thread public void Run () { Reclen--; Textview.settext ("+reclen"); Determine if the countdown is complete if (reclen<0) { //Stop Execution timer.cancel (); Hide Countdown textview.setvisibility (View.gone);}} ); }}}
2, TimerTask and handler (without timer of the improved type)
&NBSP;
public class TimerTask extends Activity {//Set a countdown private int reclen = 12; Private TextView TextView; Timer timer=new timer (); public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.timertask); textview= (TextView) Findviewbyid (r.id.txttime); After a delay of 1000 milliseconds to start execution, the second 1000 is how long the interval executes timer.schedule (task,1000,1000); TimerTask} final Handler handler=new Handler () {public void Handlemessage (Message msg) {Swit CH (msg.what) {case 1:textview.settext ("" +reclen); Determine if the countdown is complete if (reclen<0) {//Stop execution timer.cancel (); Hidden Countdown textview.setvisibility (View.gone); }}}} TimerTask task=new TimerTask () {public void run () { reclen--; Send a message to handler for processing messageMessage=new Message (); Message.what=1; Handler.sendmessage (message); } } }
}
----------younger brother Talent is not fine, if there is a mistake. Please enlighten me------
The countdown implementation in Android