2013-08-01 1 views
-1

사용자가 텍스트 필드를 채우는 동안 내 앱에서 타이머를 실행해야합니다. 나는 동시에 그것을 할 수 없었다. 사용자가 TextField를 채우지 않은 경우 (5 초) 컨트롤이 홈 스크린으로 돌아 가야한다고 가정합니다. 어떤 도움을 주시겠습니까 ??Android : TextField 사용 중에 타이머를 동시에 실행하는 방법

+2

지금까지 해본 코드입니다. –

답변

0

당신은 TimerTask

예를 사용해야합니다 : 당신이 경우 즉시 활동/사용자 폼이로드로 타이머를 시작하고자하는 사용자에게 보일 때, 당신은 당신의 활동의 onStart() 방법에 아래의 코드를 추가 할 수 있습니다 :

int timer_wait_time= 5000; // in miliseconds 
Timer timer = new Timer(); 
TimerTask myTT= new MyTimerTask(); 
timer.schedule(myTT, timer_wait_time); 

이 타이머를 시작합니다 whic h는 timer_wait_time이 지난 후에 만료됩니다. TimerTask의 run() 메소드 (여기서는 "MyTimerTask")를 실행합니다.

MyTimerTask는 다음과 같이 정의된다 :

class MyTimerTask extends TimerTask{ 

      // this method gets called when the desired time is over 
     public void run() { 
      // put your code here about what you want to do when the timer expires. 
      // maybe code to switch to other activity or disabling the text field 
     } 

} 

나는 그 당신을 도움이되기를 바랍니다.

관련 문제