Titanium Community Questions & Answer Archive

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

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!

— asked August 17th 2010 by Fernando Morgenstern
0 Comments

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

    — answered August 17th 2010 by Peter janett
    permalink
    1 Comment
    • This works, however the handler fires every time you tap anywhere in the window. Not just when tapping the tab.

      — commented August 15th 2013 by Chris Kelly
  • 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.

    — answered August 17th 2010 by David Cranwell
    permalink
    0 Comments
  • 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.

    — answered August 17th 2010 by David Cranwell
    permalink
    0 Comments
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.