Tab unfocus event?

You must Login before you can answer or comment on any questions.

Hi,

I have a TabGroup with 4 tabs. When I click on a tab, I want to know that the user has left the previous tab. Is there an event that gets fired for a tab view when it loses focus?

Thanx.

2 Answers

Under the Titanium.UI.TabGroup package you can use this event

blur Fired when this tab group loses focus. On Android, fired when a tab in this tab group loses focus.

Properties index : Number Index of the current active tab. On iOS, a value of undefined indicates that the More tab was the active tab. previousIndex : Number Index of the previous active tab. On iOS, a value of undefined indicates that the More tab was the previous tab. previousTab : Titanium.UI.Tab Previous active tab. On iOS, a value of undefined indicates that the More tab was the previous tab. source : Object Source object that fired the event. tab : Titanium.UI.Tab Active tab. type : String

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TabGroup-event-blur

Hi Norton, refer kitchen sink sample for example code... tab group has an blur event which gives you desired value like active tab, current tab, previous index, pervious tab. etc.

sample code from kitchen sink application....

self.addEventListener('focus', function(e) {
        // On iOS, the "More..." tab is actually a tab container, not a tab. When it is clicked, e.tab is undefined.
        if (!e.tab) {
            return;
        }
 
        // iOS fires with source tabGroup. Android with source tab
        if ((e.source == baseUITab) || (e.source == controlsTab) || (e.source == phoneTab) || (e.source == platformTab) || (e.source == mashupsTab) || (e.source == self)) {
 
            messageLabel.text = 'tab changed to ' + e.index + ' old index ' + e.previousIndex;
            messageWin.open();
 
            setTimeout(function() {
                Ti.API.info('tab = ' + e.tab.title + ', prevTab = ' + (e.previousTab ? e.previousTab.title : null));
                messageLabel.text = 'active title ' + e.tab.title + ' old title ' + (e.previousTab ? e.previousTab.title : null);
            }, 1000);
 
            setTimeout(function() {
                messageWin.close({
                    opacity : 0,
                    duration : 500
                });
            }, 2000);
        }
 
    }); 
 
    self.addEventListener('blur', function(e) {
        Titanium.API.info('tab blur - new index ' + e.index + ' old index ' + e.previousIndex);
    });

Your Answer

Think you can help? Login to answer this question!