3 つの要素 (2 秒ごと) を表示するアプリを実行し、それぞれが before 要素の後に表示されるようにしたいと考えています。コードは次のとおりです。
public void gameStart()
{
do
{
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
if (data == 1)
{
CountDownTimer cdt = new CountDownTimer(2000, 1000)
{
@Override
public void onTick(long millisUntilFinished)
{
element1.setVisibility(View.VISIBLE);
}
@Override
public void onFinish()
{
element1.setVisibility(View.GONE);
}
}.start();
} else if (data == 2)
{
CountDownTimer cdt = new CountDownTimer(2000, 1000)
{
@Override
public void onTick(long millisUntilFinished)
{
element2.setVisibility(View.VISIBLE);
}
@Override
public void onFinish()
{
element2.setVisibility(View.GONE);
}
}.start();
} else if (data == 3)
{
CountDownTimer cdt = new CountDownTimer(2000, 1000)
{
@Override
public void onTick(long millisUntilFinished)
{
element3.setVisibility(View.VISIBLE);
}
@Override
public void onFinish()
{
element3.setVisibility(View.GONE);
}
}.start();
} else if (data == 4)
{
CountDownTimer cdt = new CountDownTimer(2000, 1000)
{
@Override
public void onTick(long millisUntilFinished)
{
element4.setVisibility(View.VISIBLE);
}
@Override
public void onFinish()
{
element4.setVisibility(View.GONE);
}
}.start();
} else if (data == 5)
{
CountDownTimer cdt = new CountDownTimer(2000, 1000)
{
@Override
public void onTick(long millisUntilFinished)
{
element5.setVisibility(View.VISIBLE);
}
@Override
public void onFinish()
{
element5.setVisibility(View.GONE);
}
}.start();
} else if (data == 6)
{
CountDownTimer cdt = new CountDownTimer(2000, 1000)
{
@Override
public void onTick(long millisUntilFinished)
{
element6.setVisibility(View.VISIBLE);
}
@Override
public void onFinish()
{
element6.setVisibility(View.GONE);
}
}.start();
}
id = id + 1;
text.setText("cos " + id);
data = random.nextInt(6) + 1;
}
}, 2000);
} while (id <= 3);
}
しかし、アプリケーションを起動すると、遅延が始まります。アプリのシャウトダウン。私は何をすべきか?そして、私もこれを試します
public void gameStart()
{
do
{
if (data == 1)
{
element1.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
element1.setVisibility(View.GONE);
}
}, 2000);
} else if (data == 2)
{
element2.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
element2.setVisibility(View.GONE);
}
}, 2000);
} else if (data == 3)
{
element3.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
element3.setVisibility(View.GONE);
}
}, 2000);
} else if (data == 4)
{
element4.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
element4.setVisibility(View.GONE);
}
}, 2000);
} else if (data == 5)
{
element5.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
element5.setVisibility(View.GONE);
}
}, 2000);
} else if (data == 6)
{
element6.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
element6.setVisibility(View.GONE);
}
}, 2000);
}
id = id + 1;
text.setText("cos " + id);
data = random.nextInt(6) + 1;
} while (id <= 3);
}
しかし、すべての要素が同時に表示されます