在Codename One中从一个Container导航到另一个Container

时间:2014-06-03 07:48:13

标签: navigation containers codenameone

我有一个带有4个容器(标签)的主表格。在第一个容器(MessagesContainer)上我有MultiButtons。当我单击MultiButton时,我想导航到另一个容器(DetailContainer)。而且我还希望按下的MultiButton中的信息可以在DetailContainer中使用。

这是我的MultiButton:

  MultiButton mb = new MultiButton();
  mb.setTextLine1(messageContent);
  mb.setTextLine2(messageDate);
  mb.setName(messageId + "--MB");
  mb.setCheckBox(true);
  mb.setIcon(img);

  Command navigateToDetail = new Command("Detail") {
     public void actionPerformed(ActionEvent ev) {
        System.out.println("Get here!");

       //showContainer("DetailContainer", null, null);

       Component detailContainer = findDetailContainer(f);
       reloadContainer(detailContainer);

  }
};

 mb.setCommand(navigateToDetail);
 findMessagesContainer(f).addComponent(mb);

我试过showContainer,f.show()但它不起作用。我无法理解为什么导航这么傻如此痛苦?

如何显示DetailContainer并将被点击的值的MultiButton发送到DetailContainer?

1 个答案:

答案 0 :(得分:0)

如果您只想切换到其他标签,请在标签组件上使用setSelectedIndex()

但是,如果我正确理解您的问题,您希望深入了解哪些应该与showContainer一起使用,但是为此您需要使用EmbeddedContainer。通常,在使用Form导航时,功能非常简单,我们会替换整个UI。但是,当您想要使用Tab导航时,我们无法知道您要替换哪个部分。因此,您需要使用EmbeddedContainer并在其中引用通过GUI构建器创建的另一个容器(而不是表单)。然后,您可以调用showContainer()并在EmbeddedContainer层次结构中为其提供一个Component,以便我们有一个" root"找到合适的父母(假设4个标签你可以有4个EmbeddedContainer,所以我们需要知道哪一个...)。

你可以避免这一切,并使用Container.replace(),这正是我们内部所做的,但是你不会拥有"自动"从GUI构建器导航。

这不是一件轻而易举的事,但我们花了大量时间思考如何简化这一过程,并且仍然提供相同的功能集,并且空洞。

相关问题