使用自定义对话框时无法使用 onDismiss() - Android
我正在开发一个小程序,我需要添加一个自定义对话框,在关闭时将一些信息传递给调用活动。 我扩展了对话框类,当我尝试在关闭时捕获自定义对话框时,使用 onDismiss 侦听器,它永远不会到达它,因为我使用了自定义对话框。
这是我的活动的一部分 -
.
.
.
attributes customizeDialog = new attributes(con,position,pick.getLastVisiblePosition());
customizeDialog.show();
(属性是扩展对话框类的类的名称)。
这是我在对话框完成时设置的事件侦听器 -
customizeDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Log.v("LOG_CAT",attributes.selectedIndexes.get(0) + " " + attributes.selectedIndexes.get(1) + " " + attributes.selectedIndexes.get(2) + " " + attributes.selectedIndexes.get(3) + " " + attributes.selectedIndexes.get(5) + " ");
}
});
我知道我做错了,我只是不知道如何修复它。
我真的很感激任何有关这个问题的帮助。
谢谢!
I'm working on a little program, and I need to add a custom dialog that passes some info to the calling acitivity when it closes.
I extended the dialog class, and when I try to capture the custom dialog when it closes,using an onDismiss listener, it never reaches it because I used a custom dialog.
This is part of my activity -
.
.
.
attributes customizeDialog = new attributes(con,position,pick.getLastVisiblePosition());
customizeDialog.show();
(The attributes being the name of the class that extends the dialog class).
Here is the event listener I set up when the dialog finishes -
customizeDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Log.v("LOG_CAT",attributes.selectedIndexes.get(0) + " " + attributes.selectedIndexes.get(1) + " " + attributes.selectedIndexes.get(2) + " " + attributes.selectedIndexes.get(3) + " " + attributes.selectedIndexes.get(5) + " ");
}
});
I know i'm doing it wrong,I just don't know how to fix it.
I would really appreciate any help with this problem.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我倾向于让我的活动实现这样的监听器......
I tend to have my activity implement listeners like this...
您可以让您的调用活动实现一个自定义侦听器接口,该接口在对话框关闭时调用:
如果您想在除关闭之外的任何其他时间将内容发送回调用者,这尤其有用。
You could have your calling activity implement a custom listener interface that is called when the dialog closes:
This is especially useful if you want to send stuff back to the caller at any other time besides on dismissal.
如果您想在对话框内进行某种保存,则必须使用
onDicmissListener
因为对于自定义对话框,默认情况下不会调用onDismiss
:And if you want to have some sort of saving inside the dialog, again, you have to use
onDicmissListener
since for custom dialogsonDismiss
is not called by default:如果您使用自定义对话框并且无法关闭它,请尝试以下代码。
这对我有用。
If you are using custom dialog and can't dismiss it, try below code.
It worked for me.
要记住的一件事是,
OnDismissListener
正在侦听子进程的关闭。客户对话框的父级需要onDismissListener
,而不是对话框本身。“用于允许对话框创建者在对话框关闭时运行一些代码的接口。”
One thing to remember is that an
OnDismissListener
is listening for the dismiss of the child processes. The parent of your customer dialog needs theonDismissListener
, not the dialog itself."Interface used to allow the creator of a dialog to run some code when the dialog is dismissed."
要在 CustomDialog 类中添加对话框:
To add dialog inside CustomDialog class: