0

내 코드는 2 개의 카운트 다운 타이머로 구성되며, 완료 후 하나는 GO라고 표시됩니다. 다른 하나는 시작되지만 두 번째 타이머가 즉시 시작되고 GO! 메시지가 즉시 사라집니다. GO를 지연시키는 방법! 메시지 또는 두 번째 타이머가 나타 납니까? 여기에 코드가 있습니다.Android 두 카운트 다운 타이머가 겹칩니다. 두 번째 연기하는 방법?

public class WorkoutGymEasy1 extends Activity { 

CountDownTimer cdt = null; 
MediaPlayer mp = null; 
TextView c; 
Button b; 
ImageView image; 
TextView pushuptext; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.workout_gym_easy1); 
    final TextView c = (TextView) findViewById(R.id.timer_gym_easy1); 
    c.setAlpha(0f); 
    final Button b = (Button) findViewById(R.id.button1); 
    b.setAlpha(1f); 
    final ImageView image = (ImageView) findViewById(R.id.imagePushUp); 
    b.setAlpha(1f); 
    final TextView pushuptext = (TextView) findViewById(R.id.textPushUp); 
    b.setAlpha(1f); 

    RelativeLayout rl5 = (RelativeLayout) findViewById(R.id.rl5); 
    rl5.setBackgroundColor(Color.BLACK); 

    mp = MediaPlayer.create(WorkoutGymEasy1.this, R.raw.countdown); 
     try { 
      mp.prepare(); 
     } catch (IllegalStateException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     b.setOnClickListener(new OnClickListener() { 
      public void onClick (View v) { 
       b.setAlpha(0f); 
       c.setAlpha(1f); 
       mp.start(); 
       new CountDownTimer(6000, 1000) { //20 seconds count down with 1s interval (1000 ms) //access TextView element on the screen to set the timer value 
        public void onTick(long millisUntilFinished) { // Code in this method is executed every 1000ms (1s) 
         c.setText("" + (millisUntilFinished/1000) + ""); //update the timer 
         //if (millisUntilFinished == 0) { 
          //c.setText("GO!"); 
         //} 
        } 

        @Override 
        public void onFinish() { 
         // TODO Auto-generated method stub 
         c.setText("GO!"); 
         // Intent myIntent = new Intent(getApplicationContext(), WorkoutGymEasy2.class); 
         // startActivity(myIntent); 
         new CountDownTimer(31000, 1000) { //30 seconds count down with 1s interval (1000 ms) //access TextView element on the screen to set the timer value 
          public void onTick(long millisUntilFinished) { // Code in this method is executed every 1000ms (1s) 
           c.setText("" + (millisUntilFinished/1000) + ""); //update the timer 
          } 

          @Override 
          public void onFinish() { 
           // TODO Auto-generated method stub 
           Intent myIntent = new Intent(getApplicationContext(), WorkoutGymEasy2.class); 
           startActivity(myIntent); 

           finish();    // call finish() method to destroy this activity and return to instructions screen 
          } 
         }.start(); 
        } 
       }.start(); 
      } 
     }); 

} 

protected void OnPause() { 
    super.onPause(); 
    mp.release(); 
    finish(); 
} 
} 

답변

0

지연을 시뮬레이트하려면 3 개의 타이머가 필요합니다. 첫 번째 타이머가 시작되고 완료됩니다. "이동"타이머 시작하기. 그런 다음 "이동"타이머가 끝나면 두 번째 공식 타이머가 꺼집니다.

관련 문제