2016-11-11 21 views
2

形式示标签回从形式到一个特定的标签 - 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); 

我需要在这里的是,当我回去的add事件,它应该进入事件选项卡,同样,当我从添加会议选项卡返回时,它应该转到会议选项卡。我怎样才能做到这一点?

回答

0

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

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