将代码添加到代号为1的特定滑动选项卡中?

时间:2017-04-12 09:58:16

标签: codenameone

如何根据动态选项卡的选定索引值将容器添加到特定的滑动选项卡?

4 个答案:

答案 0 :(得分:1)

这是一个简单的例子,当按下按钮时,它会向当前选中的标签添加标签:


    int compIndex = 1;
    public void start() {
        if(current != null){
            current.show();
            return;
        }
        Form hi = new Form("Hi World", new BorderLayout());

        Tabs tabs = new Tabs();
        tabs.addTab("Tab 1", BoxLayout.encloseY(new Label("Tab 1")));
        tabs.addTab("Tab 2", BoxLayout.encloseY(new Label("Tab 2")));
        tabs.addTab("Tab 3", BoxLayout.encloseY(new Label("Tab 3")));

        Button btn = new Button("Add To current");

        btn.addActionListener(e->{
            ((Container)tabs.getSelectedComponent()).add("Added Component "+(compIndex++))
                    .revalidate();
        });


        hi.add(BorderLayout.CENTER, tabs).add(BorderLayout.SOUTH, btn);
        hi.show();
    }

答案 1 :(得分:0)

可以将容器添加到标签中,如下所示。

       tabs.addSelectionListener(new SelectionListener() {

            @Override
            public void selectionChanged(int oldSelected, int newSelected) {


 addComponent(newSelected)

                }
                }

                void addContainer(int index){
                Container container = new Container();
     tabs.addComponent(index, container);


        }

答案 2 :(得分:0)

void addComponent(int newSelected,NamesListBean nameListBean) {
            displayContainer   = new Container(new BoxLayout(BoxLayout.Y_AXIS));
            displayContainer.removeAll();
            for(NamesBeans names:nameListBean.getNamesList()){
                displayContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
                Label name=new Label(names.getNames());
                Log.p("names======="+names.getNames());
                //displayNamesContainer.removeAll();

                //displayNamesContainer.forceRevalidate();
                displayContainer.add(name);
            }
            //getDisplay(displayContainer);
            //Container container = new Container();
            tabs.addComponent(newSelected, displayContainer);
            displayContainer.revalidate();
        }
    });

答案 3 :(得分:0)

    public class MaskAndUnMask extends Form{
public MaskAndUnMask(Form current,Resources theme){
this.current=current;
this.theme=theme;
}
public void mask(){
Form hi = new Form("Swipe Tabs", new LayeredLayout());
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage radioEmptyImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, s);
FontImage radioFullImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, s);
((DefaultLookAndFeel)UIManager.getInstance().getLookAndFeel()).setRadioButtonImages(radioFullImage, radioEmptyImage, radioFullImage, radioEmptyImage);
nameListBean=getSwipeTabsValues(lowerBound,upperBound); 
finalRadioList=new ArrayList<String>();
radioList=new ArrayList<RadioButton>();
tabsListName=new ArrayList<String>();
borderLayoutContainer=new Container(new BorderLayout());
radioTypeContainer=new Container();
FlowLayout buttonFlowLayout = new FlowLayout();
buttonFlowLayout.setAlign(Component.CENTER);
radioTypeContainer.setLayout(buttonFlowLayout);
buttonGroup=new ButtonGroup();
displayContainer1=new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer1.setScrollableY(true);
tabs = new Tabs();
divOfRadioButton=totalRecordCount/10;
modOfRadioButton=totalRecordCount%10;
if(modOfRadioButton>0 && modOfRadioButton<9){
totalRadioButton=divOfRadioButton+1; 
}else{
totalRadioButton=divOfRadioButton;
}
displayContainer   = new Container();
for(i=0;i<totalRadioButton;i++){
displayContainer   = new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer.removeAll();
displayContainer.revalidate();
tabs.addTab("",displayContainer);
tabs.setName("t"+i);
tabs.setTabUIID(tabs.getName());
radioButton =new RadioButton();
radioButton.setName("rbt"+i);
radioTypeContainer.add(radioButton);
finalRadioList.add(radioButton.getName());
tabsListName.add(tabs.getName());
radioList.add(radioButton);
tabIndex0="rbt0";

if(radioList.get(i).getName().equals(tabIndex0)){
radioList.get(i).setSelected(true); 
getDisplay(displayContainer);
}
buttonGroup.addAll(radioButton);
}
for(int i=0;i<radioList.size();i++){
radioList.get(i).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
for(int i=0;i<radioList.size();i++){
radioButtonIndex="t"+buttonGroup.getSelectedIndex();
}
for(int i=0;i<tabsListName.size();i++){
if(radioButtonIndex!=null && radioButtonIndex.equals(tabsListName.get(i))){
tabs.setSelectedIndex(buttonGroup.getSelectedIndex());
}
}
}
});   
}
borderLayoutContainer.add(BorderLayout.SOUTH,radioTypeContainer);
tabs.addSelectionListener(new SelectionListener() {

@Override
public void selectionChanged(int oldSelected, int newSelected) {
radioButtonName="rbt"+newSelected; 
for(int i=0;i<radioList.size();i++){
if(radioList.get(i).getName().equals(radioButtonName)){
val=newSelected;
if(newSelected==0){
nameListBean = null;
lowerBound=Constants.PAGELOWERBOUND;
upperBound=Constants.PAGEUPPERBOUND;
nameListBean=getSwipeTabsValues(lowerBound,upperBound); 
addComponent(newSelected,nameListBean);
radioList.get(i).setSelected(true);
break;
}else{
nameListBean = null;
int val=newSelected;
int multipleVal=val*Constants.PAGEUPPERBOUND+1;
lowerBound=multipleVal;
upperBound=multipleVal+9;
nameListBean=getSwipeTabsValues(lowerBound,upperBound); 
addComponent(newSelected,nameListBean);
radioList.get(i).setSelected(true);
break;
}
}else{
radioList.get(i).setSelected(false);
}
}
}
void addComponent(int newSelected,NamesListBean nameListBean) {
displayContainer.removeAll();
for(NamesBeans names:nameListBean.getNamesList()){
displayContainer   = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label name=new Label(names.getNames());
displayContainer.add(name);
}
tabs.addComponent(newSelected, displayContainer);
displayContainer.revalidate();
}
});

displayContainer1.add(tabs);
displayContainer1.add(borderLayoutContainer);
hi.add(displayContainer1);
hi.show();
}