我正在开发一款游戏。 我在玩家身上使用了两个进度条作为电池。 现在我想在任何进度条清空时只显示一个对话框。 为了减少电池,我使用了计数器的逻辑,当检测到碰撞时,计数器的逻辑会减少。
BattryLevelCPU.setProgress(counter--);现在我想使用对话框来显示这个counter==0我将如何实现它? 我试过像
if counter==0{ //tried code of dialogue box }除了一堆错误,我没有任何结果。 我可以这样做吗?
If counter==0 { showDialog(DIALOG_ALERT); }`@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ALERT: Builder builder = new AlertDialog.Builder(this); builder.setMessage("This ends the activity"); builder.setCancelable(true); builder.setPositiveButton("I agree", new OkOnClickListener()); builder.setNegativeButton("No, no", new CancelOnClickListener()); AlertDialog dialog = builder.create(); dialog.show(); } return super.onCreateDialog(id); } private final class CancelOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Cancle selected, activity continues", Toast.LENGTH_LONG).show(); } } private final class OkOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { AlertExampleActivity.this.finish(); } } `I am working on a game. I have used two progressbar as a battery on the players. Now I want to simply display a dialogue box when any of the progressbar get emptied. For decreasing the battery I have used the logic of counter which get decreased as collision is detected.
BattryLevelCPU.setProgress(counter--);Now I want to use dialogue box to display when this counter==0 How I would be able to achieve it? I have tried out like
if counter==0{ //tried code of dialogue box }I haven't got any result except bunch of errors. Could I do something like this??
If counter==0 { showDialog(DIALOG_ALERT); }`@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ALERT: Builder builder = new AlertDialog.Builder(this); builder.setMessage("This ends the activity"); builder.setCancelable(true); builder.setPositiveButton("I agree", new OkOnClickListener()); builder.setNegativeButton("No, no", new CancelOnClickListener()); AlertDialog dialog = builder.create(); dialog.show(); } return super.onCreateDialog(id); } private final class CancelOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Cancle selected, activity continues", Toast.LENGTH_LONG).show(); } } private final class OkOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { AlertExampleActivity.this.finish(); } } `最满意答案
您可以通过访问它来创建一个简单的对话框
You can create a simple dialog box by visiting this
更多推荐
counter,builder,box,dialog,电脑培训,计算机培训,IT培训"/> <meta name="de
发布评论