当前位置: 代码迷 >> Android >> Android记时CountDownTimer
  详细解决方案

Android记时CountDownTimer

热度:42   发布时间:2016-04-28 05:08:21.0
Android倒计时CountDownTimer
public class MainActivity extends Activity {	private MyCount mc;	private TextView tv;	    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        tv = (TextView)findViewById(R.id.show);         mc = new MyCount(70000, 1000);         mc.start();     }    class MyCount extends CountDownTimer{		public MyCount(long millisInFuture, long countDownInterval) {			super(millisInFuture, countDownInterval);			System.out.println("你好");		}		@Override		public void onTick(long millisUntilFinished) {			Date date = new Date(millisUntilFinished);			SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");			String str = sdf.format(date);			System.out.println(str);			tv.setText("请等待70秒("+millisUntilFinished / 1000 +")...");		}		@Override		public void onFinish() {			tv.setText("finish");		}    }    @Override    protected void onDestroy() {    	super.onDestroy();    	mc.cancel();    }}

?

例如要倒计时30秒,每秒中间间隔时间是1秒,两个参数可以这样写MyCount(30000,1000)。

  相关解决方案