问题描述
我想向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);
}
1楼
// 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);