Titanium Community Questions & Answer Archive

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

setActiveTab and Android

I've discovered (and verified on the KitchenSink), that when you setActiveTab on Android to try and programmatically switch to a different tab there's a bit of weirdness if you're on a sub-window that has been opened in a Tab. These are the steps I'm talking about:

  1. Open KitchenSink
  2. On the Base UI tab, click 'Tab Groups'
    This opens a new window on the Base UI Tab and obscures the tabs which is annoying.
  3. Press "Set Active Tab (index)" (or Object, it doesn't matter). The pop-up from app.js shows that the tab index has changed, but the "Tab Groups" window is still active.
  4. Now, press the android device return key, and you navigate back to the tabGroup, you can see the tabs again, and you're now on the "Controls" tab.

Anyone have a solution on how do deal with this? How are you supposed to switch between tabs on Android?

— asked September 25th 2010 by Christopher Rumpf
  • android
  • setactivetab
  • tabgroup
  • tabs

3 Answers

  • setActiveTab doesn't work at all for me on android. The code i made works perfect on iphone, but not on android.

    — answered October 1st 2010 by Peter Griffin
    • How are you using setActiveTab. Like the KitchenSink examle? Are you trying to setActiveTab from a window that has been opened under a tab window (i.e. Ti.UI.currentTab.open(foo))? If so, from what I've seen, that doesn't seem to work as you might expect on android. It seems to set the tab you specify, but the view remains on your sub window. On iPhone it jumps the view to that active tab like you probably want. I'd still love to hear how people are accomplishing tab switches on Android. :/

      — commented October 1st 2010 by Christopher Rumpf
    • I tried:

      • changing the active tab when the tabview was opened
      • changing the active tab when the tabview was closed

      Both didn't work. I deleted the whole tabview now and use buttons to change. Works even better.

      — commented October 5th 2010 by Peter Griffin
  • From what I've gathered, this is a bug in the Titanium SDK. There's a patch available here (which I can't vouch for): https://github.com/appcelerator/titanium_mobile/commit/b5ac7e8103410d0b26520770c3f48b523164106a

    I didn't want to recompile the SDK, so as a pretty hacky work-around I set up an event to trigger the tab switch from the file in which I initialized the tabs:

    var tabGroup = Titanium.UI.createTabGroup();
    var window1 = Titanium.UI.createWindow({
      title:'Window 1',
    var window1Tab = Titanium.UI.createTab({
    var window2 = Titanium.UI.createWindow({
      title:'Window 2',
    var window2Tab = Titanium.UI.createTab({
    case 1:
    case 2:
    Ti.App.fireEvent('tabSwitch', {tab:2}); //this can be called anywhere in the project
    — answered March 27th 2011 by Noah Litvin
    1 Comment
    • If you are using at least SDK 1.6.1, you should not have to patch anything. The link you gave is just showing what had to change in the SDK to apply the fix, but according to the history for ticket 1536 it became part of the base code on one of the 1.6.0 builds last January.

      — commented March 28th 2011 by Doug Handy
  • I've talked with Appcelerator about the issue Christopher reported at the top and apparently it's default Android behavior and they have no plans to make it consistent with the iPhone.

    — answered April 22nd 2011 by Matthew Lieder
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.