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:
- Open KitchenSink
- 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. - 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.
- 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?
3 Answers
-
setActiveTab doesn't work at all for me on android. The code i made works perfect on iphone, but not on android.
-
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', url:'main_windows/win1.js' }); var window1Tab = Titanium.UI.createTab({ title:"Win1", window:window1 }); tabGroup.addTab(window1Tab); var window2 = Titanium.UI.createWindow({ title:'Window 2', url:'main_windows/win2.js' }); var window2Tab = Titanium.UI.createTab({ title:"Win2", window:window2 }); tabGroup.addTab(window2Tab); tabGroup.open(); Ti.App.addEventListener('tabSwitch',function(data){ switch(data.tab) { case 1: tabGroup.setActiveTab(window1Tab); break; case 2: tabGroup.setActiveTab(window2Tab); break; default: tabGroup.setActiveTab(window1Tab); } }); Ti.App.fireEvent('tabSwitch', {tab:2}); //this can be called anywhere in the project
-
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.