Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Is there a way to manage tab order in a tab group?

As per the title, is there a way to manage the tab order of tabs in a tabGroup aside from the order that addTab() is called? For example, if you're later adding a new tab to an already established tabGroup and you want to ensure that it's somewhere besides at the end, how do you accomplish that?

Thanks.

— asked April 21st 2010 by Christopher Rumpf
  • tabgroup
  • tabs
0 Comments

1 Answer

  • Hello everyone,

    I searched for this solution everywhere, but as I found I broke a little
    the head and did work. I'm going like, to facilitate those who need

    
    // Create Tab Group
    var tabGroup = Ti.UI.createTabGroup();
    
    // Create Windows
    var win1 = Ti.UI.createWindow();
    var win2 = Ti.UI.createWindow();
    var win3 = Ti.UI.createWindow();
    var win4 = Ti.UI.createWindow();
    var win5 = Ti.UI.createWindow();
    var win6 = Ti.UI.createWindow();
    var win7 = Ti.UI.createWindow();
    
    // Create Tabs
    var tab1 = Ti.UI.createTab({ 
        id:1, 
        window:win1
    });
    var tab2 = Ti.UI.createTab({ 
        id:2, 
        window:win2
    });
    var tab3 = Ti.UI.createTab({ 
        id:3, 
        window:win3
    });
    var tab4 = Ti.UI.createTab({ 
        id:4, 
        window:win4
    });
    var tab5 = Ti.UI.createTab({ 
        id:5, 
        window:win5
    });
    var tab6 = Ti.UI.createTab({ 
        id:6, 
        window:win6
    });
    var tab7 = Ti.UI.createTab({ 
        id:7, 
        window:win7
    });
    
    
    
    // Save Tab order on Pause/Exit
    Ti.App.addEventListener('pause', function(e){
        for(i=0;i<7;i++){
            Ti.App.Properties.setString('TB'+i,tabGroup.tabs[i].id);
        }
    });
    
    
    
    // Load Tabs in Order
    for(i=0;i<7;i++){
    
        // Try to get saved values for Tab Order
        k = Ti.App.Properties.getString('TB'+i);
        if(k==null){
            // If don't have saved, populate in Designer order
            eval('tabGroup.addTab(tab'+(i+1)+');'); 
        }else{
            // if have saves, populate
            eval('tabGroup.addTab(tab'+k+');');  
        }
    
    }
    
    
    // Set First Tab Active
    tabGroup.setActiveTab(0); 
    
    // Open 
    tabGroup.open();
    
    — answered April 4th 2011 by Adriano Paladini
    permalink
    3 Comments
    • Hi,

      this doesn't work for me because nothing is done in the "pause" event.
      I've added a log :

      Ti.App.addEventListener('pause', function(e){
          Titanium.API.debug("THE APP HAS BEEN pause !");
          for(i=0;i<9;i++){
              Titanium.API.debug("TB"+i);
              Ti.App.Properties.setString('TB'+i,tabGroup.tabs[i].id);
          }
      });
      

      but nothing is logged, apart from this :
      [DEBUG] fire app event: pause

      How can I make the "pause" work ???

      — commented December 7th 2011 by Florent Rtitanium
    • Tip: You can store your tabs in an array, and then avoid using eval like this:

      var tabs = [];
      
      tabs.push(Ti.UI.createTab({ … }));
      
      ...
      
      tabGroup.addTab(tabs[i]);
      

      — commented July 6th 2012 by Kristof Gruber
    • eval == evil

      — commented September 4th 2012 by michael schouman
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.