异常在android系统对话框内创建对话框 [英] Exception creating dialog inside a dialog in android

查看:123
本文介绍了异常在android系统对话框内创建对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对夫妇一个对话框,对话框内被抛出异常的:

I have a couple of dialogs inside a dialog that are throwing the exception:

02-10 15:52:45.592: ERROR/AndroidRuntime(321): java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 2

在code是:

dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                ....

           showDialog(ID_DIALOG_SEND);

对话框定义如下:

The dialog is defined as follows:

 @Override
 protected Dialog onCreateDialog(int id) {
        switch (id) {

    case ID_DIALOG_SEND:

        ProgressDialog loadingDialog = new ProgressDialog(this);
        loadingDialog.setMessage("Sending...");
        loadingDialog.setIndeterminate(true);
        loadingDialog.setCancelable(false);
        return null;
      ....

和它并不适用于该对话框工作,要么:

And it doesn't work for this dialog either:

Builder b = new AlertDialog.Builder(this);

case ID_DIALOG_ERR:
b.setMessage("Error")
        .setCancelable(false)
        .setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        return null;

任何提示?

感谢

推荐答案

由于您要使用的ShowDialog(ID_DIALOG_SEND); 在一个匿名内部类,它会给你一个问题,因为它认为ShowDialog的是内部类的方法。您需要引用外Activity类,其中包含为它工作。所以你的情况我会做:

Because you are trying to use showDialog(ID_DIALOG_SEND); in an Anonymous Inner class, it will give you a problem, as it thinks ShowDialog is a method of the inner class. You need to reference the outer Activity class, in which it is contained for it to work. So in your case i would do :

dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", 
 new DialogInterface.OnClickListener() {                 
    public void onClick(DialogInterface dialog, int which) {

           ....             

     thisActivityClassName.showDialog(ID_DIALOG_SEND);

thisActivityClassName.this.showDialog(ID_DIALOG_SEND);

否则,如果失败,则可能需要创建一个处理程序与外部类进行通信。

Otherwise if this fails, you might need to create a Handler to communicate with the outer class.

另外,我完全同意,并重申dave.c的答复。

Also, i fully agree and reiterate dave.c's reply.

这篇关于异常在android系统对话框内创建对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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