스톱워치 클래스는 이렇게 구성되어있습니다. ( StopWatch.java)

 

public class StopWatch {
 private long start_time = 0;
 private long stop_time = 0;
 private long time = 0;
 
 private boolean running = false;
 
 public void init(){
  this.start_time = 0;
  this.stop_time = 0;
  this.running = false;
 }
 
 public void start(){
  this.start_time = System.nanoTime();
  this.running = true;
 }
 
 public void end(){
  this.stop_time = System.nanoTime();
  this.running = false;  
 }
 
 public double calTime() {
  double cal_time = 0.0;
  
  if(running){
   time = (System.nanoTime() - start_time)/1000000;
  }else{
   time = (stop_time - start_time)/1000000;
  }

  cal_time = Double.parseDouble(String.format("%02f", (time/1000.0)));
  return cal_time;
 }
}

 

 

 

핸들러 타이머는

 

Handler timer = new Handler(){
   public void handleMessage(Message msg){
    String timer = String.format("%.02f", sw.calTime());
    
    int len = timer.length();
    if(len != 6){
     while(6 - len++ > 0)
      timer = "0" + timer;
    }
    //text_time.setText(timer);
    //canvas.drawText("Time:" + timer.toString(), 10, 100, mPaint);
    sendEmptyMessage(0);
    super.handleMessage(msg);
   }
  };  

 

 

이렇게 되어있는데 원래 예제를 따왔을때는 보통 스톱워치시간을 TextView를 이용하여 쓰더라구요.

 

그래서 핸들러 안에서 //text_time.setText(timer); 이렇게 해주면 시간을 계속찍는것 같았습니다.

 

근데 저는 canvas를 이용하여 (onDraw) 모든걸 표현하고 있는데,

 

그렇게하려면 //canvas.drawText("Time:" + timer.toString(), 10, 100, mPaint); 와 같은방법으로 해주어야 합니다.

 

근데 핸들러안에 canvas가 존재하지 않고,  canvas가 onDraw안에서 성립되어야하는건데..

 

어떻게 해야 onDraw(Canvas canvas)에서도 찍힐 수 있는지 궁금합니다.ㅠㅠ