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});
});
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' }); }
});