Stian
Stian

Reputation: 13

Closing a dialog when clicking outside it in codename one

I have a custom dialog created with the Codename One designer. It's a simple dialog with a title and 2 buttons. The dialog is shown after a button click:

showForm("ContactDialog", null);

Now I would like the dialog to hide if the user taps anywhere on the screen outside the dialog boundaries, so the user can cancel the dialog without requiring a dedicated "cancel" button. Is this possible within the Codename One framework?

For reference, the behaviour I am trying to reproduce, can be seen in the Snapchat friend dialog.

Upvotes: 1

Views: 110

Answers (1)

Diamond
Diamond

Reputation: 7483

Creating a new instance of the Dialog and call setDisposeWhenPointerOutOfBounds(true), then change the way the dialog was shown.

Dialog dlg = (Dialog) createContainer("/theme", "ContactDialog");
dlg.setDisposeWhenPointerOutOfBounds(true);
dlg.show();

Upvotes: 3

Related Questions