Is it possible to add a click event to a tab?
Hi,
I have a "logout tab" and i'm trying to add an click event but it is not working. My code looks like this:
var logoutTab = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Logout'
});
logoutTab.addEventListener('click', function() {
alert( 'test' );
});
When i click at this tab, it opens a black window but does not shows me the alert.
Am i doing something wrong or tabs just doesn't support click events?
Thank you!
3 Answers
-
Accepted Answer
I'm not sure this is exactly what you are looking for, but I did something similar but fired the event on the tabs focus.
In other words, instead of adding an event listener on click of the tab, add the listener on focus of the tab.
Hope that helps,
Peter Janett
-
Fernando:
These questions I raised previously may partially answer your questions:
http://developer.appcelerator.com/question/48981/how-do-you-execute-code-which-refers-to-a-particular-tab-each-time-that-tab-and-only-that-tab-is-focused
http://developer.appcelerator.com/question/27971/does-android-not-get-the-window-events-blur-and-focus
In essence - Tab, tabgroup and window events as a whole, are at worst broken and at best inconsistently supported across iPhone/Android.
From what I can tell you should be listening for click events on the tabGroup, not the tab, but you'll have trouble working out which tab was clicked due to another bug in the Android portion which incorrectly reports the tab index.
I've been struggling for too long and I'd actually recommend you don't use Titanium.
-
Fernando:
These questions I raised previously may partially answer your questions:
http://developer.appcelerator.com/question/48981/how-do-you-execute-code-which-refers-to-a-particular-tab-each-time-that-tab-and-only-that-tab-is-focused
http://developer.appcelerator.com/question/27971/does-android-not-get-the-window-events-blur-and-focus
In essence - Tab, tabgroup and window events as a whole, are at worst broken and at best inconsistently supported across iPhone/Android.
From what I can tell you should be listening for click events on the tabGroup, not the tab, but you'll have trouble working out which tab was clicked due to another bug in the Android portion which incorrectly reports the tab index.
I've been struggling for too long and I'd actually recommend you don't use Titanium.