Titanium Community Questions & Answer Archive

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

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();
— asked March 31st 2010 by Mark Peace
  • android
  • back
  • tabgroup
0 Comments

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?

    — answered May 5th 2010 by Fredrik Motin
    permalink
    0 Comments
  • 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.

    — answered March 31st 2010 by Don Thorp
    permalink
    0 Comments
  • 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?

    — answered March 31st 2010 by Mark Peace
    permalink
    0 Comments
  • I have the same problem eventhough i create a new wind to hold the tabGroup.

    Anyone has a clue?

    Thanks…

    — answered November 8th 2010 by LAY Oro
    permalink
    0 Comments
  • 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
    });

    — answered September 3rd 2013 by justin key
    permalink
    1 Comment
    • I should add that if the window you add the fullscreen: false to is the first window you need to add exitOnClose: true otherwise when you hit back it shows a blank screen and you have to hit back twice:
      var app = Ti.UI.createWindow({ backgroundColor:'black', exitOnClose: true, fullscreen : false });

      — commented September 4th 2013 by justin key
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.