从表单返回到特定选项卡 - codenameone

时间:2016-11-11 11:30:12

标签: codenameone

表格有标签

Tabs tabs = new Tabs(Component.BOTTOM);
tabs.addTab("Events", wrapContainerSingleTable);
tabs.addTab("Business Meetings", wrapContainerSingleTableMeeting);

Button addEventButton = new Button("Add Event ");
FontImage.setMaterialIcon(addEventButton, FontImage.MATERIAL_ADD);
wrapContainerSingleTable.add(FlowLayout.encloseRight(addEventButton));

addEventButton.addActionListener((e) -> {
    showForm("AddEvent", null);
});

Button addMeetingButton = new Button("Add Meeting ");
FontImage.setMaterialIcon(addMeetingButton, FontImage.MATERIAL_ADD);
wrapContainerSingleTableMeeting.add(FlowLayout.encloseRight(addMeetingButton));

addMeetingButton.addActionListener((e) -> {
    showForm("AddMeeting", null);
});

返回addEvent和addMeeting表单:

Command back = new Command("Back", backBtn) {
    @Override
    public void actionPerformed(ActionEvent evt) {
        showForm("MeetingsAndEvents", this);
    }

};
back.putClientProperty("uiid", "RoundTableBack");
f.setBackCommand(back);
t.addCommandToLeftBar(back);

我需要的是,当我从添加事件返回时,它应该转到事件选项卡,同样当我从添加会议选项卡返回时,它应该转到会议选项卡。我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

尝试在actionPerformed()方法的Tabs组件上使用setSelectedIndex()。

答案 1 :(得分:0)

将此添加到您的状态机:

protected void storeComponentState(Component c, Hashtable destination) {
   super.storeComponentState(c, destination);
   if(c instanceof Tabs) {
        destination.put("TabSel" + c.getName(), ((Tabs)c).getSelectedIndex());
   }
}

protected void restoreComponentState(Component c, Hashtable destination) {
   super.restoreComponentState(c, destination);
   if(c instanceof Tabs) {
        Integer i = (Integer)destination.get("TabSel" + c.getName());
        if(i != null) {
           ((Tabs)c).setSelectedIndex(i.intValue());
        }
   }
}