timeRemaining
变量是表示0-10范围内的整数的字符串。我想要完成的是运行timerTask一段timeRemaining
秒,然后转到以i++
开头的以下代码。但是,当我运行此方法时,i++
部分立即执行,并且计时器任务根本不执行。它基本上应该从timeRemaining
倒数到0并将时间减少到0然后继续使用其余的代码。
public void resumeSlideShow(Integer i, final String timeRemaining, int offset) {
timer = new Timer();
Button time_rem = (Button) findViewById(R.id.time_rem);
time_rem.setBackgroundResource(R.drawable.hex_filled);
final TimerTask finish_photo = new TimerTask() {
@Override
public void run() {
SlideShow.this.runOnUiThread(new Runnable() {
@Override
public void run() {
TextView time_rem = (TextView) findViewById(R.id.time_rem);
int timeRem = Integer.parseInt(timeRemaining);
timeRem--;
time_rem.setText(Integer.toString(timeRem));
if (timeRem == 0) {
timer.cancel();
}
}});
}};
timer.scheduleAtFixedRate(finish_photo,0,1000);
i++;
if (i < imageDisplayerArrayList.size()) {
timer.cancel();
timer = new Timer();
slideshow(imageDisplayerArrayList, i, offset, timeRemaining);
}
else {
timer.cancel();
Intent qa = new Intent(SlideShow.this,ViewScreen.class);
startActivity(qa);
finish();
}
}