我有一对夫妇一个对话框,对话框内被抛出异常的:
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系统对话框内创建对话框
发布评论