Titanium Community Questions & Answer Archive

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

Android: Window events not working with Tabgroup #Titanium 1.2

Hi,

I have created a tabgroup on app.js as


   var tabGroup = Titanium.UI.createTabGroup();

   var win1 = Titanium.UI.createWindow({
        url:'home.js',
        backgroundColor:'#FFFFFF'
          });


   var tab1 = Titanium.UI.createTab({  
        title:'Home',
        window:win1
          });

   tab1.addEventListener('click',function(){

       Ti.API.info('Loading..'); // Doesn't Work

   });        


   var win2 = Titanium.UI.createWindow({
            url:'search.js',
            title:'Search',
            backgroundColor:'#fff',
            barColor:'#000000'
        });



   var tab2 = Titanium.UI.createTab({  
            title:'Search',
            window:win2
        });


   tabGroup.addTab(tab1);  
   tabGroup.addTab(tab2);  


    // open tab group
   tabGroup.open();

Then in home.js


var win=Titanium.UI.currentWindow;

win.addEventListener('open',function{

   loaddata(); // Doesn't Work

});

win.addEventListener('blur',function{

   loaddata(); // Doesn't Work

});


win.addEventListener('focus',function{

   loaddata(); // Doesn't Work

});

var tab=Titanium.UI.currentTab;

tab.addEventListener('click',function(){

   loaddata(); // Doesn't Work

});


loaddata(); //Obviously works


function loaddata(){
  // I want to call this function everytime the tab is opened

  Ti.API.info('Loading..');

}

None of the events are getting called. I want to call the "loaddata" function whenever the home tab is called.

As far as I have noticed, when we use tabgroup, it opens any tab only once, like iPhone viewDidLoad() function works, and when you click the tab once again it just shows the window.

Any work around, or, is this a bug. As I have found a bug filed in as (links) #Titanium0.9.3

— asked April 30th 2010 by Ved Prakash
  • android
  • tabgroup
  • tabs
  • windowevents
0 Comments

3 Answers

  • Try this:

    tabGroup.addEventListener('focus', function(event) {
      tabGroup.activeTab.window.fireEvent('focus', {});
    });
    

    This works for me. You might need to create a real event object if your listeners use it.

    — answered September 9th 2011 by Calvin Yu
    permalink
    2 Comments
    • i can catch focus with android. thank you.

      — commented September 23rd 2011 by Junichi Otake
    • worked for me, thanks!

      — commented September 23rd 2011 by Gui Barthel
  • You can attach the listener to the tabGroup. It is not working properly with Android, but you can use this nasty hack. It works for me on Android platform:

    tabGroup.addEventListener('focus', function(e)
    {
        setTimeout(function()
        {       
            Ti.API.debug('tab changed to ' + tabGroup.activeTab);        
        },100);
    });
    

    Ticket for this bug.

    — answered August 27th 2010 by Lukasz Radziwonowicz
    permalink
    3 Comments
    • I have the same issue as the poster and I don't understand this hack, as all it does is log which tab you are on. What code would go within the setTimeout to make the active window reload?

      — commented November 3rd 2010 by Justin Toth
    • same issue, when i add a focus event to a window (in a tab on a tabgoup) the focus event fires but only once, if i revisit the window the event does not fire at all.

      — commented April 21st 2011 by dan harvey
    • ps, this is 1.6.1 and tried 1.6.2 as well, still not working!

      — commented April 21st 2011 by dan harvey
  • I'd love to see a resolution or a hack around this. I'm struggling to wake up the camera again after revisiting the view.

    — answered June 19th 2011 by Kristian Luoma
    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.