TabGroup and Back Button (Android)
Hi all,
I'm trying to write an interface which starts with a tableview menu, and then goes into a tabgroup when an option is clicked. I can get it working, but the back button is closing the app rather than going back to the tableview.
Can anyone shed light on this? Here's my code
var tabGroup = Ti.UI.createTabGroup()
tabGroup.addTab(Titanium.UI.createTab({
title:'Tab1',
window: Ti.UI.createWindow()
}));
tabGroup.addTab(Titanium.UI.createTab({
title:'Tab2',
window: Ti.UI.createWindow()
}));
tabGroup.addTab(Titanium.UI.createTab({
title:'Tab3',
window: Ti.UI.createWindow()
}));
var table = Ti.UI.createTableView({
data: [
{title:'test1'},
{title:'test2'}
]
})
table.addEventListener ('click', function(e) {
tabGroup.open();
})
var app = Ti.UI.createWindow({
backgroundColor:'black'
});
app.add(table);
app.open();
5 Answers
-
I am wondering the same thing. Having a TabGroup with three tabs that represent three "steps" in a checkout process. A press on the back button of course should not close the app, but rather open the tab/step before.
How do one trap the back button press and assign it a custom action instead of closing the app?
-
Try creating a second window that is launched from your tableview menu. Have that second window use a url and in the code it points to, create your tabgroup and tabs.
-
Thanks for your reply. When I try this, I have to press 'back' twice to go back to the tableview; once takes me to the window I created, and twice to the tableview.
Any clues?
-
I have the same problem eventhough i create a new wind to hold the tabGroup.
Anyone has a clue?
Thanks…
-
According to the documentation
"On Android, only one tab group may exist at one time. A tab group may be closed to allow a new one to be opened later, but the root of the application must be a heavyweight window to prevent it exiting." So make your window heavyweight.var app = Ti.UI.createWindow({
backgroundColor:'black',
modal: true,
fullscreen : false
});