1. public class Countdown extends Activity{  
  2.     private int time = 30;  //初始化时间
  3.  
  4.     public void onCreate(Bundle savedInstanceState){  
  5.         super.onCreate(savedInstanceState);  
  6.   
  7.         setContentView(R.layout.countdown);
  8.         handler.postDelayed(runnable, 1000);  
  9.     }     
  10.   
  11.     Handler handler = new Handler();  
  12.     Runnable runnable = new Runnable() {  
  13.         @Override  
  14.         public void run() {  
  15.           time--;
  16.           if(time>0){
  17.              handler.postDelayed(this1000);  //public final boolean postDelayed(Runnable r, 
  18.                                                               //long delayMillis)
                                                                  //从当前时间开始延迟delayMillis时间后执行Runnable
  19.            }
  20.         }  
  21.     };  

 

   原文地址:http://blog.csdn.net/ithomer/article/details/6903084

相关文章:

  • 2021-04-22
  • 2021-08-12
  • 2021-07-21
  • 2021-04-21
  • 2021-07-13
  • 2021-04-18
  • 2021-12-05
  • 2021-12-20
猜你喜欢
  • 2021-08-10
  • 2021-07-14
  • 2021-08-05
  • 2021-07-05
  • 2021-08-13
  • 2021-09-20
  • 2021-04-23
  • 2021-05-04
相关资源
相似解决方案