使用对话框(Using dialogue box)

编程入门 行业动态 更新时间:2024-10-26 14:26:57
使用对话框(Using dialogue box)

我正在开发一款游戏。 我在玩家身上使用了两个进度条作为电池。 现在我想在任何进度条清空时只显示一个对话框。 为了减少电池,我使用了计数器的逻辑,当检测到碰撞时,计数器的逻辑会减少。

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

本文发布于:2023-08-07 00:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458953.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   dialogue   box

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!