반응형



1. Thread
Thread 시작
float threadValue = 100; new Thread(new Runnable() { @Override public void run() { while(threadValue >= 0) { runOnUiThread(new Runnable() { @Override public void run() { tv_thread.setText(String.format("%.2f", threadValue)); } }); try { Thread.sleep(10); threadValue -= 0.01; } catch (Exception e) { e.printStackTrace(); } } } }).start();
Thread 종료
threadValue = 0; tv_thread.setText(threadValue + "");
2. Timer
Timer 시작
float timerValue = 100; TimerTask timerTask = new TimerTask() { @Override public void run() { tv_timer.setText(String.format("%.2f", timerValue)); timerValue -= 0.01; } }; new Timer().schedule(timerTask, 0, 10);
Timer 종료
timerTask.cancel();
3. CountDownTimer
CountDownTimer 시작
float countdowntimerValue = 100; CountDownTimer countDownTimer = new CountDownTimer(100000, 10) { @Override public void onTick(long millisUntilFinished) { tv_countdowntimer.setText(String.format("%.2f", millisUntilFinished/1000.)); } @Override public void onFinish() { tv_countdowntimer.setText("완료"); } }; countDownTimer.start();
CountDownTimer 종료
if(countDownTimer != null) countDownTimer.cancel();
프로젝트 소스 다운↓↓↓
ThreadTimer.zip
0.48MB
반응형
'안드로이드' 카테고리의 다른 글
Android Animation(View Property) (0) | 2021.11.17 |
---|---|
Android 로딩바 동적 생성, 해제 (0) | 2021.11.14 |
Android Fragment (0) | 2021.11.14 |
Android ViewPager (0) | 2021.11.14 |
Android Webview(Remote, Local) (2) | 2021.11.14 |
최근댓글