# 변수 선언 부분
CountDownTimer timer;
// 타이머 전체 초 : 60초
long millisInFuture = 60000; # final long millisInFuture 을 선언시 앱 실행 후 타이머를 변경할수 없다.
// 타이머 감소시킬 초 : 1초
final int countDownInterval = 1000;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timer = new CountDownTimer(millisInFuture,countDownInterval)
{
// 1초가 지날때 마다 어떤걸 할걸지
@Override
public void onTick(long l)
{
int remain = (int) l / 1000;
// long remain = l / 1000;
// 두개 다 사용 가능
txtTimer.setText("남은시간 : " + remain);
}
// 초가 다 지났을떄 어떤걸 할건지
@Override
public void onFinish()
{
Log.i("MyTimer","타이머 끝났다");
isFinish = true;
}
}
}
사용방법이 나와있는 URL
https://developer.android.com/reference/android/os/CountDownTimer
CountDownTimer | Android Developers
android.net.wifi.hotspot2.omadm
developer.android.com
| Android - 액티비티간의 화면 전환 방법 (0) | 2022.07.13 |
|---|---|
| Android - AlertDialog 사용법 (0) | 2022.07.12 |
| Android - 앱 타이틀,상태바 컬러 바꾸는 방법 (0) | 2022.07.12 |
| Android - 스크롤뷰 사용법 (0) | 2022.07.12 |
| Android - JSON 데이터 파싱하는 방법 (0) | 2022.07.12 |