Java 代码名一-对话框关闭/取消/点击外部的事件侦听器
我正在通过代号1移植我的Android应用程序 现在我正在我的应用程序中移植对话框 我能够在Codename项目中创建类似的对话框,将ActionListeners添加到按钮中,等等,但是我无法找到cancel/Dislose/tap outside event的事件监听器 dispose()方法没有相应的侦听器,这将非常有用 这是最简单的对话框,但我也有更复杂的对话框:Java 代码名一-对话框关闭/取消/点击外部的事件侦听器,java,android,codenameone,actionlistener,Java,Android,Codenameone,Actionlistener,我正在通过代号1移植我的Android应用程序 现在我正在我的应用程序中移植对话框 我能够在Codename项目中创建类似的对话框,将ActionListeners添加到按钮中,等等,但是我无法找到cancel/Dislose/tap outside event的事件监听器 dispose()方法没有相应的侦听器,这将非常有用 这是最简单的对话框,但我也有更复杂的对话框: public static void openAlertDialog( String s1, String s2) {
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();
}
当对话框被取消但没有按下按钮时,如何有机会执行某些代码?对于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
}
这很简单,但是编译器说show()返回void。对不起,我的错误。忘记修复调用以使用
showDialog()
纠正了示例中的错误