Titanium Community Questions & Answer Archive

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

How to Open the Second Tab in a Tabgroup

I am tring to make it so that when a user clicks on a button, btn2, they will be taken to the second tab in a tabgroup. Using the code below, I am only able to get the first tab to load.

btn2.addEventListener('click',function(e)
{
  win1.close({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT});
  tabGroup1.setActiveTab(e.tabStry).open();
});
— asked October 18th 2010 by Drew Watkins
  • button
  • tabgroup
  • tabgroup.setactivetab
0 Comments

3 Answers

  • Accepted Answer

    In a click event the variable (in this case e) would only hold globalPoint, x,y, source and type. The most useful is source but unfortunately it would be the button itself in this case. None of those would have access to tabStry so e.tabStry would always evaluate to null. Since tabStry is more or less global, you could say

    tabGroup1.setActiveTab(tabStry).open();
    

    Thanks for the code sample, it helped me understand what you were trying to do. Let me know if this helped.

    — answered October 18th 2010 by John McKnight
    permalink
    0 Comments
  • Unless there is some other code that you aren't showing, this line of code can't work as expected.

      tabGroup1.setActiveTab(e.tabStry).open();
    

    There is no e.tabStry in a click event so you would get either a NULL or 0 which would likely cause the first tab to be selected. Try replacing e.tabStry with a real value (e.g. 1,2,3, etc) or a variable that has been defined and see if it helps.

    — answered October 18th 2010 by John McKnight
    permalink
    0 Comments
  • Sorry, I'm very new to this stuff. I have only been working with appcelerator for a few days and this is my first time posting to the message board. I did define tabStry as one of the tabs. My complete code is below.

    //Create tab group
    var tabGroup1 = Titanium.UI.createTabGroup();
    
    //Create About Window
    var winAbt = Titanium.UI.createWindow({  
        title:'About Us',
        backgroundColor:'#183b63',
        barColor:'#000',
        url:'winAbt.js'
    });
    var tabAbt = Titanium.UI.createTab({  
        icon:'images/icons/group.png',
        title:'About Us',
        window:winAbt
    });
    
    //Create Story Window
    var winStry = Titanium.UI.createWindow({  
        title:'The Story',
        backgroundColor:'#183b63',
        barColor:'#000',
        url:'winStry.js'
    });
    var tabStry = Titanium.UI.createTab({  
        icon:'images/icons/book.png',
        title:'Story',
        window:winStry
    });
    
    // add tabs to tab group
    tabGroup1.addTab(tabAbt);  
    tabGroup1.addTab(tabStry);
    
    // Define Home Screen Buttons
    var btn1 = Titanium.UI.createButton({
        title:'About Us',
        width:'264',
        height:'55',
        left:'32',
        top:'135',
        backgroundImage:'images/btnRed.png'
    });
    var btn2 = Titanium.UI.createButton({
        title:'The Story',
        width:'264',
        height:'55',
        left:'32',
        top:'215',
        backgroundImage:'images/btnRed.png'
    });
    
    // build home screen
    win1.add(btn1);
    win1.add(btn2);
    win1.open();
    
    btn1.addEventListener('click',function(e)
    {
       win1.close({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT});
       tabGroup1.open();
    });
    btn2.addEventListener('click',function(e)
    {
       win1.close({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT});
       tabGroup1.setActiveTab(e.tabStry).open();
    });
    
    — answered October 18th 2010 by Drew Watkins
    permalink
    0 Comments
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.