异常在android系统对话框内创建对话框

编程入门 行业动态 更新时间:2024-10-23 20:15:48
本文介绍了异常在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系统对话框内创建对话框

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

发布评论

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

>www.elefans.com

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