Search code examples
lwuitcodenameone

Closing dialog on action of button in codename one


I make a dialog in which we have some buttons.

on action of one of that button i want to finish dialog.

I don't want to add any command in it.

Please help.

Here is my code.

Form form = (Form) createContainer("/theme", "MYDialog1"); Container container = (Container) findByName("Container", form); button = new Button(new Command("Close"),i)); try { button.setUIID("LabelButton"); } catch (Exception exception) { exception.printStackTrace(); } button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ?????? } }); container.addComponent(button); Dialog.show("", form, null);


Solution

  • If you add a command to a dialog it will dispose the dialog by default.

    You can manually invoke dialog.dispose() to close the dialog, to get the current dialog just use Dialog dlg = (Dialog)Display.getInstance().getCurrent();