2017-04-12 47 views

回答

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


     } 
+0

我建立在滑動凸片4單選按鈕動態。 如何將包含項目列表的特定選定容器添加到選擇選項卡(在滑動或選擇單選按鈕上)? –

+0

我已編輯我的答案 – tizbn

+0

我已將上面的代碼添加到上面但無法顯示 –

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

我添加了上面的代碼,但當單擊或滑動特定的選項卡時它什麼也沒有顯示 –

+0

您如何調用此方法? 請添加表格的完整代碼。 – tizbn

+0

我添加代碼我如何調用方法 –

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

請添加完整的完整代碼 – tizbn

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(); 
    } 
相關問題