Codename One-对话框关闭/取消/点击外部的事件监听器

问题描述 投票:1回答:1

我正在通过代号One移植我的Android应用。

现在我正在将对话框移植到我的应用程序中。

我能够在Codename项目中创建类似的对话框,将ActionListeners添加到按钮上,依此类推,但是我找不到用于在事件外部取消/关闭/点击的事件监听器。

dispose()方法没有相应的侦听器,这将很有用。

这是最简单的对话框,但是我也有更复杂的对话框:

public static void openAlertDialog( String s1, String s2)
{
   Dialog alertDialog=new Dialog(s1);
    Button okButton=new Button("ok");
    alertDialog.setLayout(BoxLayout.y());
    Container c1=new Container(); //not so useful here but when there are more buttons
    c1.setLayout(BoxLayout.x());
    alertDialog.add(new SpanLabel(s2, "DialogBody"));
    c1.add(okButton);
    alertDialog.add(c1);
    alertDialog.show();
}

当关闭对话框但未按下任何按钮时,如何有机会执行一些代码?

java android codenameone actionlistener
1个回答
0
投票

您甚至不需要为Codename One对话框使用事件侦听器。例如。该代码可以这样写:

Dialog alertDialog=new Dialog(s1);
Command ok = new Command("ok");
Button okButton=new Button(ok);
alertDialog.setLayout(BoxLayout.y());
Container c1=new Container(); //not so useful here but when there are more buttons
c1.setLayout(BoxLayout.x());
alertDialog.add(new SpanLabel(s2, "DialogBody"));
c1.add(okButton);
alertDialog.add(c1);
alertDialog.setDisposeWhenPointerOutOfBounds(true);
if(alertDialog.showDialog() == ok) {
    // user pressed OK. You can test against other commands than ok as well
} else {
    // canceled or clicked outside
}
© www.soinside.com 2019 - 2024. All rights reserved.