Android的 - AlertDialog不显示从主方法调用时 [英] Android - AlertDialog doesn't show when called from Main-Method

查看:287
本文介绍了Android的 - AlertDialog不显示从主方法调用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,一个AlertDialog。在code效果很好,当我把它放在一个按钮的onClick侦听器,但是当我把它放在我的主方法的结束并不在所有的工作。

I've got a problem with an AlertDialog. The code works well, when I put it in a onClick-Listener of a Button, but it doesn't work at all when I put it at the end of my main-method.

这是显示AlertDialog方法:

This is the Method that shows the AlertDialog:

void showMaths(){
    AlertDialog.Builder alert = new AlertDialog.Builder(LabyRiddle.this);

    alert.setTitle("Title");
    alert.setMessage("Message");

    // Set an EditText view to get user input 
    final EditText input = new EditText(LabyRiddle.this);
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
      }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
      }
    });

    alert.create();  // <== Doesn't make any difference whether its here or not
    alert.show();
}

我只是想,主要的法运行,并在它的结束,出现的警告......

I just want that the main-method runs and at the end of it, the alert appears...

但它不会出现,而且它不会崩溃,甚至给出错误报告。

But it doesn't appear, and it doesn't crash or even give an error report.

还是有其他方式来显示警报的主要方法完成后?

Or is there another possibility to show the alert after the main method has finished?

感谢,并有一个愉快的一天!

Thanks, and have a nice day!

奥利弗

推荐答案

我认为你需要调用

alert.create().show();

在调用显示(); ,你必须用创建建设者的对话框创建(); 方法

这篇关于Android的 - AlertDialog不显示从主方法调用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆