change tab with a button

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

Hello people,

Platform: iOS

I have in my app one tabbar:

var win1 = Titanium.UI.createWindow({  
    url:'home.js',
    titleid:'XY',
    barColor: '#0B72B5'
});
var tab1 = Titanium.UI.createTab({  
    icon: 'YX',
    title:'XY',
    window:win1
});
var win2 = Titanium.UI.createWindow({  
    url:'inhalt.js',
    titleid:'XY',
    barColor: '#0B72B5'
});
var tab2 = Titanium.UI.createTab({  
    icon: 'YX',
    title:'XY',
    window:win2
});
tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  
 
tabGroup.open();
Is it possible when a tab is opened, a button on the side of the tabbar to create responsive and you can navigate by clicking the button in the tabs?

With best regards

1 Answer

Accepted Answer

yes, use this method to set the active tab

tabGroup.setActiveTab(tabIndex);

— answered 10 months ago by Javier Rayon
answer permalink
3 Comments
  • no, the problem is - that the tabgroup defined in app.js - but the content is in home.js. i need a connection to the var of app.js to change it.

    thanks for answer!

    — commented 10 months ago by Jonathan Schneider

  • ok, so you need to acces tabGroup from win1, is that correct? In that case, you can pass tabGroup itself as an argument of win1, so it will be available in home.js

    app.js:

    var tabGroup = Ti.UI.createTabGroup();
     
    var win1 = Titanium.UI.createWindow({  
        url:'home.js',
        titleid:'XY',
        barColor: '#0B72B5',
        tabGroup: tabGroup
    });
    then, in home.js
    var win = Ti.UI.currentWindow;
     
    var tabGroup = win.tabGroup;
     
    //then use in your button event listener, like
     
    btn.addEventListener('click', function(){
     //set the active tab by its index number
        tabGroup.setActiveTab(tabIndex); 
    });
    Just note that using multiple execution context is considered a bad practice, I suggest you to move your code to commonJS.

    — commented 10 months ago by Javier Rayon

  • perfect! it works fine. thanks :)

    — commented 10 months ago by Jonathan Schneider

Your Answer

Think you can help? Login to answer this question!