2013-08-19 60 views
0

我在以色列擔任足球(足球)裁判員,我被要求編寫一個應用程序來模擬即將到來的賽季的健身測試。 該測試是一個間隔測試,用戶可以輸入他跑了多少次,走多少次以及多少次。 每次啓動/停止運行時都會發出蜂鳴聲(beep變量的類型爲MediaPlayer)。每次完成跑步/行走時,計時錶應該重置。android天文臺時間間隔和重置

下面的代碼幾乎工程 - 嗶聽到聲音在正確的時間和集數權後停止,但畫面卡住的計時錶開始之後...

我會很感激你善意的幫助! 謝謝,Yaad

private void testLoop() { 
    int i = 0; 
    boolean flag = true; //true = running, false = walking 
    chronometer.setBase(SystemClock.elapsedRealtime()); 
    chronometer.start(); 

    //run, walk, rep = integers that are set by user input 

    beep.start(); 
    tvRunWalk.setText("Running"); 
    tvRepNum.setText(String.format("Repetition Number: %d", i + 1)); 
    while (i < rep) //rep = number of repetitions 
    { 
     if (SystemClock.elapsedRealtime() - chronometer.getBase() == run * 1000 && flag) //if running time is over and you are now running 
     { 
      chronometer.setBase(SystemClock.elapsedRealtime()); 
      flag = false; 
      tvRunWalk.setText("Walking"); 
      beep.start(); 
     } 
     else if (SystemClock.elapsedRealtime() - chronometer.getBase() == walk * 1000 && !flag) //if walking time is over and you are now walking 
     { 
      chronometer.setBase(SystemClock.elapsedRealtime()); 
      flag = true; 
      i++; 
      tvRunWalk.setText("Running"); 
      tvRepNum.setText(String.format("Repetition Number: %d", i + 1)); 
      beep.start(); 
     } 
    } 
} 

回答