android之Handler Runnable实现倒计时
- public class Countdown extends Activity{
- private int time = 30; //初始化时间
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.countdown);
- handler.postDelayed(runnable, 1000);
- }
- Handler handler = new Handler();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- time--;
- if(time>0){
- handler.postDelayed(this, 1000); //public final boolean postDelayed(Runnable r,
- //long delayMillis)
//从当前时间开始延迟delayMillis时间后执行Runnable - }
- }
- };
- }
原文地址:http://blog.csdn.net/ithomer/article/details/6903084