我在以色列担任足球(足球)裁判,我被要求编写一个应用程序来模拟我们即将到来的赛季的体能测试。该测试是间隔测试,用户可以输入他跑步、步行的时间和组数。每次启动/停止运行时都会发出哔声(beep
变量类型为MediaPlayer
)。每次完成跑步/步行后,计时器应重置。
以下代码几乎可以工作 - 在正确的时间听到哔声并在正确的组数后停止,但在计时器启动后屏幕立即卡住......
非常感谢您的帮助!谢谢,亚德
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();
}
}
}