1

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

vikrant kumar
  • 208
  • 2
  • 14

2 Answers2

4

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

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
0

You Don't any relationship between the dialog and the container. Because this reason you can't dispose dialog.

What i understand from your question is that you won't to use command because you want your gui for button.

My advice is to create dialog like that (I think is can be work):

Dialog dialog = new Dialog();
    Display.getInstance().callSerially(new Runnable() {
        public void run() {
            dialog.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
            ...
            dialog.addComponent(dialog);

            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) 
                    {
                        dialog.dispose();//???????????
                    }

            dialog.addCommand(okCommand);
            ...
            dialog.show();
        }
    });

this dialog need to be class member to be recognized by button.

neb1
  • 209
  • 1
  • 12