我如何显示 3 个吐司,每个吐司延迟 1 秒
How i can show 3 Toasts with delay of 1 second for each
我想显示 Toast
3 次,每次延迟 1 秒,在第 3 次敬酒后我的游戏重新开始。
这是我的代码,通过这个 toast 只显示一次,持续 3 秒,然后我的游戏重新开始。
toast = new Toast(this);
TextView textView=new TextView(this);
textView.setTextColor(Color.CYAN);
textView.setBackgroundColor(Color.TRANSPARENT);
textView.setTextSize(40);
textView.setText("Game will be start again in 3 seconds");
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(textView);
// Here is the dialog when i press "NO" button then toast appear for 3 seconds just one's.
alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// dialog.cancel();
// GamePanel.thread.resume();
dialog.dismiss();
timer = new CountDownTimer(3000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
toast.show();
}
@Override
public void onFinish() {
toast.cancel();
GamePanel.thread.setRunning(true);
}
}.start();
return;
}
}
);
alertDialog.show();
return true;
}
return super.onKeyDown(keyCode, event);
}
// show toast 1
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// show toast 2.
}
}, 3000);
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// show toast 3.
}
}, 6000);
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// Init game.
}
}, 7000);
我想显示 Toast
3 次,每次延迟 1 秒,在第 3 次敬酒后我的游戏重新开始。
这是我的代码,通过这个 toast 只显示一次,持续 3 秒,然后我的游戏重新开始。
toast = new Toast(this);
TextView textView=new TextView(this);
textView.setTextColor(Color.CYAN);
textView.setBackgroundColor(Color.TRANSPARENT);
textView.setTextSize(40);
textView.setText("Game will be start again in 3 seconds");
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(textView);
// Here is the dialog when i press "NO" button then toast appear for 3 seconds just one's.
alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// dialog.cancel();
// GamePanel.thread.resume();
dialog.dismiss();
timer = new CountDownTimer(3000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
toast.show();
}
@Override
public void onFinish() {
toast.cancel();
GamePanel.thread.setRunning(true);
}
}.start();
return;
}
}
);
alertDialog.show();
return true;
}
return super.onKeyDown(keyCode, event);
}
// show toast 1
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// show toast 2.
}
}, 3000);
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// show toast 3.
}
}, 6000);
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// Init game.
}
}, 7000);