1 package exm.timer;
2
3 import java.util.*;
4
5 import android.app.Activity;
6 import android.os.Bundle;
7 import android.util.*;
8 import android.view.*;
9 import android.view.View. Listener;
10 import android.widget.*;
11
12 public class TimerExample extends Activity {
13
14 private TimerTask mTimer;
15 private Button mBtnStart, mBtnStop;
16 private Timer timer = new Timer();
17
18 /-* Called when the activity is first created. *-
19 @Override
20 public void onCreate(Bundle savedInstanceState) {
21 super.onCreate(savedInstanceState);
22 setContentView(R.layout.main);
23
24 initSetting();
25 btnEvent();
26 }
27
28 private void initSetting() {
29 mBtnStart = (Button) findViewById(R.id.btnstart);
30 mBtnStop = (Button) findViewById(R.id.btnstop);
31 }
32
33 private void btnEvent() {
34 mBtnStart.set Listener(new Listener() {
35
36 @Override
37 public void (View v) {
38 TimerMethod();
39 }
40 });
41
42 mBtnStop.set Listener(new Listener() {
43
44 @Override
45 public void (View v) {
46 stopTimer();
47 }
48 });
49 }
50
51 private void TimerMethod() {
52 mTimer = new TimerTask() {
53
54 @Override
55 public void run() {
56 Log.d("TIMER", "" + System.currentTimeMillis());
57 }
58 };
59
60 timer.schedule(mTimer, 2000, 3000);
61 }
62
63 private void stopTimer() {
64 // timer.cancel();
65 mTimer.cancel();
66 }
67
68 }
2
3 import java.util.*;
4
5 import android.app.Activity;
6 import android.os.Bundle;
7 import android.util.*;
8 import android.view.*;
9 import android.view.View. Listener;
10 import android.widget.*;
11
12 public class TimerExample extends Activity {
13
14 private TimerTask mTimer;
15 private Button mBtnStart, mBtnStop;
16 private Timer timer = new Timer();
17
18 /-* Called when the activity is first created. *-
19 @Override
20 public void onCreate(Bundle savedInstanceState) {
21 super.onCreate(savedInstanceState);
22 setContentView(R.layout.main);
23
24 initSetting();
25 btnEvent();
26 }
27
28 private void initSetting() {
29 mBtnStart = (Button) findViewById(R.id.btnstart);
30 mBtnStop = (Button) findViewById(R.id.btnstop);
31 }
32
33 private void btnEvent() {
34 mBtnStart.set Listener(new Listener() {
35
36 @Override
37 public void (View v) {
38 TimerMethod();
39 }
40 });
41
42 mBtnStop.set Listener(new Listener() {
43
44 @Override
45 public void (View v) {
46 stopTimer();
47 }
48 });
49 }
50
51 private void TimerMethod() {
52 mTimer = new TimerTask() {
53
54 @Override
55 public void run() {
56 Log.d("TIMER", "" + System.currentTimeMillis());
57 }
58 };
59
60 timer.schedule(mTimer, 2000, 3000);
61 }
62
63 private void stopTimer() {
64 // timer.cancel();
65 mTimer.cancel();
66 }
67
68 }
'Android_Programma' 카테고리의 다른 글
android 지금 서비스가 동작 중인지 확인하는 코드 (0) | 2012.03.21 |
---|---|
Android softkeyboard 에 따른 event 발생 시키기 (0) | 2012.03.21 |
안드로이드 bluetooth uuid 에 관한 내용 (0) | 2012.03.21 |
Inflater XML 두개 겹쳐서 화면에 출력 시키기. (0) | 2012.03.21 |
카메라 모드에서 줌 효과주기. (0) | 2012.03.21 |