2015年4月29日 星期三

[Android] 倒數計時功能

第一個參數是總共計時幾秒,以0.001為單位,因此要讓它倒數5秒就要乘上5*1000,
第二個參數是每隔幾秒跳一次,一樣以0.001為單位,因此每隔一秒跳一次就是傳入1000。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
new CountDownTimer(5000, 1000) {

 @Override

 public void onTick(long millisUntilFinished) {
                //倒數秒數中要做的事
  textView.setText("倒數時間:" + new SimpleDateFormat("s").format(millisUntilFinished));
 }

 @Override
 public void onFinish() {
                 //倒數完成後要做的事
 }
}.start();
參考網站:
http://givemepass.blogspot.tw/2011/12/blog-post_08.html

沒有留言:

張貼留言