2013-02-15 2 views
0

기본적으로 심장 기능을 수행하고 서로 세 개의 카운트 다운 타이머를 연속적으로 배치하므로 하나의 타이머가 끝나면 다음 타이머가 시작됩니다. 하나는 준비 시간, 다른 하나는 운동 시간, 다른 하나는 휴식 시간입니다. 사용자는이 시간을 선택합니다.카운트 다운 타이머가 루핑되지 않음

사용자가 numberpicker에서 여러 번 선택하면 되겠지만 아무리해도 한 번만 실행되고 반복되지 않으므로 모든 기능이 작동한다는 것을 알 수 있습니다. 일하지 마라.

여기에 뭔가가 있습니까? 이 작업을 수행하는 더 좋은 방법이 있습니까?

//Main countdown timers loop 
    for(int i = 0; i <= times.getValue() + 1; i++) //times NumberPicker 
    { 
     prepCountTimer = new CountDownTimer(_finalPrep * 1000, 1000) { 

      public void onTick(long millisUntilFinished) { 

       tvRoundCount.setText("Round " + roundCount + "/" + times.getValue()); 
       tvCountDown.setText((millisUntilFinished/1000) + "s"); 
       if(millisUntilFinished <= (6 * 1000)) 
       { 
        tvCountDown.setTextColor(Color.RED); 
       } 
      } 

      public void onFinish() { 
       workoutCountTimer = new CountDownTimer(_finalWorkout * 1000, 1000) { 

        public void onTick(long millisUntilFinished) { 
         tvCountDown.setTextColor(Color.GREEN); 
         tvCountDown.setText((millisUntilFinished/1000) + "s"); 
         if(millisUntilFinished <= 6 * 1000) 
         { 
          tvCountDown.setTextColor(Color.RED); 
         } 
        } 

        public void onFinish() { 
         restCountTimer = new CountDownTimer(_finalRest * 1000, 1000) { 

          public void onTick(long millisUntilFinished) { 
           tvCountDown.setTextColor(Color.GREEN); 
           tvCountDown.setText((millisUntilFinished/1000) + "s"); 
           if(millisUntilFinished <= 6 * 1000) 
           { 
            tvCountDown.setTextColor(Color.RED); 
           } 
          } 

          public void onFinish() { 
           roundCount = roundCount + 1; 
          } 
          }.start(); 
        } 
        }.start(); 
      } 
      }.start(); 

    } 

답변

0

여기서 prepCountTimer을 작성하고 마침표를 지정한 다음 시작하십시오. 그 다음에는 각각과 루프의 끝에 도달하여 다시 preopCountTimer을 만들고 시작합니다. 완료되면 restCountTimer이 다음 preopCountTimer으로 시작해야합니다. 내가 여기 뭔가 잘못 이해하지 않는 한.

public void callingMethod() { 
    timerMethod(times.getValue()); 
    // execution continues as your timer will run in a different thread 
} 

public void timerMethod(final int count) { 
    if (count == 0) { 
     // we have done the number of timers we want we can 
     // call whatever we wanted to once our timers were done 
    } 
    //you could use count to get the times for each timer here 
    startTimer(_finalPrep, new timerListner() { 
     @Override 
     public void timerFinish() { 
      //when timer 1 finishes we will start timer 2 
      startTimer(_finalWorkout, new timerListner() { 
       @Override 
       public void timerFinish() { 
        //when timer 2 finishes we will start timer 3 
        startTimer(_finalRest, new timerListner() { 
         @Override 
         public void timerFinish() { 
          //when timer 3 finishes we want to call the next timer in the list. 
          timerMethod(count - 1); 
         } 
        }); 
       } 
      }); 
     } 
    }); 
} 

private interface timerListner { 
    void timerFinish(); 
} 

public void startTimer(int timerTime, final timerListner onFinish) { 
    // you can pass in other parameters unqiue to each timer to this method aswell 
    CountDownTimer timer = new CountDownTimer(timerTime * 1000, 1000) { 
     public void onTick(long millisUntilFinished) { 
      tvRoundCount.setText("Round " + roundCount + "/" + times.getValue()); 
      tvCountDown.setText((millisUntilFinished/1000) + "s"); 
      if (millisUntilFinished <= (6 * 1000)) { 
       tvCountDown.setTextColor(Color.RED); 
      } 
     } 

     @Override 
     public void onFinish() { 
      onFinish.timerFinish(); 
     } 
    }; 
    timer.start(); 

} 
+0

어떻게하면됩니까? 나는 사용자가 선택한 것에 따라 x 번 반복하지 않는 이유를 이해하지 못한다 ... – user1875797

+0

나는 어떻게 대답 할 수 있는지 보여주기 위해 나의 대답을 편집했다. – Eluvatar

관련 문제