달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
2013. 2. 15. 04:11

안드로이드 - 타이머 샘플 안드로이드 이야기2013. 2. 15. 04:11

728x90
반응형

안드로이드 - 타이머 샘플

출처:http://micropilot.tistory.com/entry/Android-Timer-Example

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

public class CountDownTest extends Activity {

TextView tv; //textview to display the countdown

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

tv = new TextView(this);
this.setContentView(tv);

/*2.5초 동안 0.5초마다 카운트다운 설정
  * 카운트다운 시작 후 매 0.5초마다 onTick() 콜백
  * 남은 시간이 0초일때 onFinish() 콜백
  */
MyCount counter = new MyCount(5000,1000);

counter.start();

}


//countdowntimer is an abstract class, so extend it and fill in methods
public class MyCount extends CountDownTimer{

public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}

@Override
public void onFinish() {
tv.setText(”done!”);
}

@Override
public void onTick(long millisUntilFinished) {
tv.setText(”Left: ” + millisUntilFinished/1000);

}

}
}

728x90
반응형
:
Posted by mapagilove