2016/03/14

Android 倒數計時器

倒數計時可以分為兩種

1.可重複的  使用 Thread

2.不可重複的 使用 CountDownTimer()

官網的解釋:
http://developer.android.com/reference/android/os/CountDownTimer.html

Public Methods


public final synchronized void cancel ()

Added in API level 1
Cancel the countdown.

public abstract void onFinish ()

Added in API level 1
Callback fired when the time is up.

public abstract void onTick (long millisUntilFinished)

Added in API level 1
Callback fired on regular interval.
Parameters
millisUntilFinishedThe amount of time until finished.

public final synchronized CountDownTimer start ()

Added in API level 1
Start the countdown.
除了start(),cancel以外

就是onFinish() ->倒數結束以後要幹嘛?

onTick()->每次減少固定單位時間時要做甚麼?

 new CountDownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
     }

     public void onFinish() {
         mTextField.setText("done!");
     }
  }.start();

CounDownTimer(總共倒數多少秒 , 每次扣多少)

每1000為一秒, 所以30000 = 30 秒 , 1000 = 1秒

範例為倒數30秒,每次扣一秒.

Related Posts:

  • 2006.11.12 38MM 自拍練習買了K100D ,一直沒時間出去照像也沒有MD,只好搞自拍感覺還滿不錯的...… Read More
  • 2007.01.04 我的相機之路2002年 EPSON 920Z當時這台非常的紅,C/P值非常的高,還有F2.0大光圈這是我第一台DC,一直以來,都覺的它很稱值,和同事們的其他品牌相比一點都不遜色,直到2005的一次出遊,不小心整個包包都摔到了920Z的鏡頭伸縮出了問題,無法正常對焦,年代久遠,也沒有修的必要了2005年 FUJI… Read More
  • 2006.11.19 43MM構圖練習43MM 拍風景,果然還是太長了,取景取了很久好不容易按下快門定焦真的能夠學習如何構圖,但旅遊真的會很不方便… Read More
  • 名琴與名家之戀佳士得拍賣公司22日將在紐約拍賣一把Stradivari小提琴與一把Goffriller大提琴不知道這次拍賣會以多少價格賣出,又是誰來標得名琴呢?相關介紹:http://www.christies.com/promos/apr05/1417/specialist.asp… Read More
  • 2006.09.17 D70S 試拍星期天,真無聊,借了同事的D70S,隨手亂拍了幾張快門,快門,很爽的感覺,DSLR 果然是不同    … Read More

0 意見: