Use more than one TabGroup and link to them with a TableView

You must Login before you can answer or comment on any questions.

Hi, I´m a very beginner with Titanium and I haven´t found any good example for this yet.

I want to use one single window as root with a TableView which links to different TabGroups e.g. this could look like this:

root window

Then I´d like to link TabGroups like Windows in the rows of this TableView. If you click on "Go to TabGroup 1" there sould be a slide effect and a TabGroup should appear:

tabgroup

My sample Code for this would look something like this for the root window:

app.js

Titanium.UI.setBackgroundColor('#000');
 
var main_window = Titanium.UI.createWindow({
    title:'main window',
    backgroundColor:'#fff',
});
 
var data = [
    {title:'Go to TabGroup 1', hasChild:true, test:'TabGroup1.js'},
    {title:'Go to TabGroup 2', hasChild:true, test:'TabGroup2.js'}
];
 
var tableview = Titanium.UI.createTableView({
    data:data
});
 
tableview.addEventListener('click', function(e) {
    if (e.rowData.test) {
        var tabgroup = Titanium.UI.createTabGroup({
            title:e.rowData.title,
            url:e.rowData.test
        });
        main_window.open(tabgroup,{animated:true});
    }
});
 
main_window.add(tableview);
 
main_window.open();
TabGroup1.js
var tabGroup = Titanium.UI.currentTabGroup();
 
var backButton = Ti.UI.createButton({title: 'Back'});
 
// add window, tab and label 1
var win1 = Titanium.UI.createWindow({
    title:'Tab 1 of TabGroup 1',
    backgroundColor:'#fff',
        leftNavButton:backButton
});
var tab1 = Titanium.UI.createTab({
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});
var label1 = Titanium.UI.createLabel({
    color:'#999',
    text:'I am Window 1',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});
win1.add(label1);
 
// add window, tab and label 2
var win2 = Titanium.UI.createWindow({
    title:'Tab 2 of TabGroup 1',
    backgroundColor:'#fff',
        leftNavButton:backButton
});
var tab2 = Titanium.UI.createTab({
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});
var label2 = Titanium.UI.createLabel({
    color:'#999',
    text:'I am Window 2',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});
win2.add(label2);
 
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
 
tabGroup.setActiveTab(1);
//win1.open();
The whole Code

Any idea how this works? I´ve read somewhere that it´s not possible to have more than one TabGroup? This can´t be true right?

all the best and thx, Jakob :)

1 Answer

Accepted Answer

Yes, you can only have one TabGroup in android. And you can't alter the tabgroup once you create it. I think it might be possible to destroy the tabgroup and create another, but I haven't seen it done.

If cross-platform is a concern, you might need to consider other ways to handle this. More ideas in this thread

Your Answer

Think you can help? Login to answer this question!