如何根據選項卡的索引值動態地將容器添加到特定的滑動選項卡?將容器添加到代號爲1的特定滑動選項卡?
1
A
回答
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
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
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();
}
相關問題
- 1. 將pull2refresh添加到代號1中的選項卡
- 2. 爲選項卡式內容添加不錯的滑動效果
- 3. 如何在代號1中的滑動選項卡中添加拉到新選項?
- 4. JqWidget選項卡 - 動態添加ajax內容的選項卡
- 5. 如何將動態生成的ajax內容追加到jquery ui選項卡中新添加的選項卡?
- 6. 將選項卡動態添加到navbarPage並選擇新選項卡
- 7. 動態添加選項卡到選項卡控件
- 8. 動態添加選項卡
- 9. 動態添加選項卡
- 10. 將HoverIntent添加到jQuery UI選項卡
- 11. 將新選項卡添加到TabControl
- 12. 如何將選項卡添加到TabView
- 13. jQuery的 - 滑動內容選項卡,滑開/關上點擊
- 14. 如何將選項卡添加到選項卡欄控制器? (iOS)
- 15. 選擇滑塊選項卡中選定的導航項並添加類
- 16. Twitter的引導 - 動態添加/刪除選項卡和選項卡內容
- 17. 滑動選項卡 - NullPointerException - Toolbar.getTitle()
- 18. 滑動選項卡主機
- 19. 將選定的選項添加到Select2
- 20. 如何使用jquery將內容添加到動態創建的選項卡
- 21. 如何添加ImageView的滑動選項
- 22. AngularJS。將$ watch添加到特定型號
- 23. 將ListView動態添加到TabHost中的選項卡
- 24. 將數據從選項卡1傳遞到選項卡2
- 25. 將新的viewcontroller添加到選項卡控制器
- 26. 將選項卡欄控制器添加到UISplitViewController的根視圖?
- 27. 鏈接到特定選項卡/直接到選項卡
- 28. 在滑動選項卡布局上添加按鈕
- 29. 如何將選項卡添加到給定的tabcontrol?
- 30. 使用GWT中的選項卡動態添加選項卡
我建立在滑動凸片4單選按鈕動態。 如何將包含項目列表的特定選定容器添加到選擇選項卡(在滑動或選擇單選按鈕上)? –
我已編輯我的答案 – tizbn
我已將上面的代碼添加到上面但無法顯示 –