package com.androidcountdowntimer2; import android.app.Activity; import android.os.Bundle; import android.os.CountDownTimer; import android.widget.TextView; /** * Android倒计时功能的实现(CountDownTimer) * @author zhongyao * */ public class MainActivity extends Activity { private MyCount mc; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView)findViewById(R.id.show); mc = new MyCount(30000, 1000); mc.start(); } /*定义一个倒计时的内部类*/ class MyCount extends CountDownTimer { public MyCount(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval); } @Override public void onTick(long millisUntilFinished) { tv.setText("请等待:" + millisUntilFinished / 1000 + "秒..."); } @Override public void onFinish() { tv.setText("finish"); } } @Override protected void onDestroy() { super.onDestroy(); mc.cancel(); } }
Android倒计时功能的实现(CountDownTimer)
原文:http://blog.csdn.net/u012440207/article/details/41015131