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
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.
-
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.
-
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.