P5music
P5music

Reputation: 3327

Codename One - event listener for Dialog dismiss/cancel/tap outside

I am porting my Android app by means of Codename One.

Now I am porting the Dialogs in my app.

I am able to create similar dialogs in the Codename project, adding ActionListeners to the buttons and so on, but I am not able to find the event listener for cancel/dismiss/tap outside event.

The dispose() method has not a corresponding listener, that would be useful.

This is the simplest Dialog, but I have more complex ones too:

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();
}

How to have the chance of executing some code when the dialog is dismissed but no buttons were pressed?

Upvotes: 2

Views: 110

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

You don't even need event listeners for Codename One dialogs. E.g. this code can be written like that:

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
}

Upvotes: 1

Related Questions