我想在android中寫一個從3開始計數到0的倒數計時器。先出現3個然後消失和2個出現等等。我搜查了很多,但我找不到任何好的樣本。你能幫我嗎?我該怎麼辦?Android倒數計時器
10
A
回答
18
使用CountDownTimer
例如:
import android.os.CountDownTimer;
MyCount timerCount;
public class TestCountdown extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
timerCount = new MyCount(3 * 1000, 1000);
timerCount.start();
}
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
//some script here
}
@Override
public void onTick(long millisUntilFinished) {
//some script here
}
}
}
6
Android中的好人想到了你。
你有一個類 - CountDownTimer
。
0
我不會寫這個代碼,但這應該不難。只需使用一個線程來顯示值3(使用說TextView)然後睡覺說(假設你希望它改變100毫秒後1秒),然後減少並重復。
一個例子是
for i=0 to 3
print the number
thread.sleep(100)
相關問題
- 1. 修復倒計時倒數計時器
- 2. 倒計時 - iPhone倒數計時器
- 3. 倒數計時器
- 4. 倒數計時器
- 5. 倒數計時器
- 6. 倒數計時器?
- 7. 倒計時器爲Android
- 8. Android ProgressBar計時器倒計時
- 9. Android倒數計時器至今
- 10. 倒數計時器需要在Android
- 11. Android中的倒數計時器錯誤
- 12. android倒計時
- 13. 倒計時器
- 14. Android中的定時器倒計時
- 15. Android ProgressBar倒計時
- 16. 倒數計時器在PHP
- 17. JavaScript倒數計時器
- 18. 倒數計時器C#
- 19. 5秒倒數計時器
- 20. 使用倒數計時器
- 21. jQuery的倒數計時器
- 22. 倒數計時器問題
- 23. Javascript倒數計時器
- 24. 隨機倒數計時器
- 25. 如何倒數計時器
- 26. PHP倒數計時器
- 27. 倒數計時器迅速
- 28. 流星:倒數計時器
- 29. iPhone sdk:倒數計時器
- 30. 倒數計時器通知
使用的AsyncTask :) – pgsandstrom 2012-04-04 12:04:30
檢查這一點 - https://stackoverflow.com/a/47695735/ 6244429 – 2017-12-07 13:42:47