【问题标题】:Closing dialog on action of button in codename one关闭代号一中按钮操作的对话框
【发布时间】:2013-02-27 20:48:28
【问题描述】:

我创建了一个对话框,其中有一些按钮。

在我想要完成对话框的那个按钮之一的操作上。

我不想在里面添加任何命令。

请帮忙。

这是我的代码。



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

【问题讨论】:

    标签: lwuit codenameone


    【解决方案1】:

    如果您将命令添加到对话框,它将默认处置该对话框。

    您可以手动调用dialog.dispose()关闭对话框,获取当前对话框只需使用Dialog dlg = (Dialog)Display.getInstance().getCurrent();

    【讨论】:

      【解决方案2】:

      你在对话框和容器之间没有任何关系。因为这个原因你不能处理对话框。

      我从你的问题中了解到,你不会使用命令,因为你想要你的 gui 按钮。

      我的建议是创建这样的对话框(我认为可行):

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

      此对话框需要是类成员才能被按钮识别。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多