Reputation: 623
has anyone know how to change window's view when tabbed bar is pressed in titanium? i've created tabbed bar and i don't know how to handling that event..
here's my code:
if (Titanium.Platform.osname === 'iphone'){
var headerDetailTabbedBar = Titanium.UI.iOS.createTabbedBar({
labels:['Header', 'Detail'],
backgroundColor:'#336699',
style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
top:10,
height:25,
width:'85%',
index:0
});
//View Mode
var btnBack = Titanium.UI.createButton({
title:'Back',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
var btnEdit = Titanium.UI.createButton({
title:'Edit',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
//Save Mode
var btnCancel = Titanium.UI.createButton({
title:'Cancel',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
var btnSave = Titanium.UI.createButton({
title:'Save',
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
subMenuDisplayEditWindow.setLeftNavButton(btnBack);
subMenuDisplayEditWindow.setRightNavButton(btnEdit);
subMenuDisplayEditWindow.add(headerDetailTabbedBar);
headerDetailTabbedBar.addEventListener('click',function(e){
if(e.index === 0){
//What should i do?
}
else{
//What should i do?
}
});
}
all i want is to change window's view with other view when the tabbed bar is pressed.. any suggestion?? thanks in advance..
Upvotes: 0
Views: 2133
Reputation: 96
var window = Ti.UI.createWindow();
var headerDetailTabbedBar = Titanium.UI.iOS.createTabbedBar({
labels : ['Header', 'Detail'],
backgroundColor : '#336699',
style : Titanium.UI.iPhone.SystemButtonStyle.BAR,
top : 10,
height : 25,
width : '85%',
index : 0
});
window.add(headerDetailTabbedBar);
var view1 = Ti.UI.createView({
backgroundColor : 'white',
top : 50
});
var view2 = Ti.UI.createView({
backgroundColor : 'red',
top : 50
});
window.add(view2);
window.add(view1);
headerDetailTabbedBar.addEventListener('click', function(e) {
if (e.index == 0) {
view1.visible = true;
view2.visible = false;
} else {
view1.visible = false;
view2.visible = true;
}
});
window.open();
just change the visibility of the view on click.
Upvotes: 4