Titanium Community Questions & Answer Archive

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

Button Bar with two buttons and two new views

I'm trying to create a button bar with two buttons that open two separate window views. I've managed to get both buttons to appear (and can get ONE new window to open up using the code below) but how do I get each button to point to a separate view? Should I use an If/Else statement? Can anyone provide me with sample code with a button bar (with two or more buttons) where each button create a new window when pressed. Thanks.

John

var win = Titanium.UI.currentWindow;

// TOOLBAR

var bb2 = Titanium.UI.createButtonBar({
labels:['Awards', 'Recommended'],
backgroundColor:'maroon'
});


var flexSpace = Titanium.UI.createButton({
systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});


win.setToolbar([flexSpace,bb2,flexSpace]);
bb2.addEventListener('click', function()
{
        bb2.labels = ['Awards'];
        win = Titanium.UI.createWindow({
        url:'../examples/views.js',
        title:'View 1',
        backgroundColor:'#fff',
        barColor:'#111',
});

Titanium.UI.currentTab.open(win,{animated:true});
});
— asked September 19th 2010 by John Howell
  • bar
  • button
  • createbuttonbar
  • mobile
  • twop
  • views
0 Comments

1 Answer

  • Accepted Answer

    bb2.addEventListener('click', function(e)
    {

    if (e.index == 0)
    {
        bb2.labels = ['Awards'];
        win = Titanium.UI.createWindow({
        url:'../views.js',
        title:'View 1',
        backgroundColor:'#fff',
        barColor:'#111'        
    });
    }
    else
    {
        bb2.labels = ['Recommended'];
        win = Titanium.UI.createWindow({
        url:'../views.js',
        title:'View 1',
        backgroundColor:'#fff',
        barColor:'#111'            
    });
    }
    

    });

    — answered September 20th 2010 by Varun Atluri
    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.