No reaction from eventListener at Ti.UI.Label
Hi,
i have a problem with the EventListener for Ti.UI.createLabel. As you can see in the code below, i made some windows with their associated tabs. When i choose the second tab, all contacts from the mobile are displayed. After click on a contact and the adress data, the alert dialog should appear, but he doesn't.
When i change the createView method call to createWindow, the event listener reacts. When i choose createWindow, all the tabs aren't displayed. With createView, they are still visible, so i had to choose createView.
Does anyone have an idea on how to fix this?
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title:'Karte',
backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Karte',
window:win1
});
// create Contact Window with associated tab
var win2 = Titanium.UI.createWindow({
title:'Kontakte',
backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'Kontakte',
window:win2
});
...
// Getting data for later processing
var people = Titanium.Contacts.getAllPeople();
var rows = [];
for (var i = 0; i < people.length; i++) {
rows[i] = Ti.UI.createTableViewRow({
title:people[i].fullName,
person:people[i],
hasChild:true
});
rows[i].addEventListener('click', function(e) {
var display = Ti.UI.createView({
backgroundColor:'#FFF',
title:e.row.person.fullName
});
win2.add(display);
var top = 0;
for (var label in e.row.person.address) {
var addrs = e.row.person.address[label];
for (var i = 0; i < addrs.length; i++) {
var info = Ti.UI.createLabel({
text:'('+label+')\n'+addrs[i].Street+ "\n" +addrs[i].City,
top:top,
left:20,
height:'auto',
width:'auto'
});
display.add(info);
...
// TODO: No reaction from event listener
info.addEventListener('click', function(e) {
var dialog = Ti.UI.createAlertDialog({
title: 'Navigation',
message: 'Die Navigation startet jetzt!',
buttonNames: ['OK']
});
dialog.show();
dialog.addEventListener('click', function(e) {
// OK button pressed
if (e.index == 0) {
...
};
});
});
}
}
tab2.open(display,{animated:true});
});
}
return rows;
var tableview = Ti.UI.createTableView({
data:contactTabData
});
win2.add(tableview);
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
// open tab group
tabGroup.open();
Regards,
Stefan
4 Answers
-
Stefan,
You can't open tab2, as there is no open() event for tabs. See Titanium.UI.Tab.
I'm not sure whether that's the underlying issue, though so you would have to try it and let us know.
Also, if you are simply closing the AlertDialog when the OK button is clicked, using the cancel:0 property reduces your code.
Hope this is useful
-
Thanks for the information Hal.
I know that method open aren't in the documentation of Ti.UI.Tab class, but I found it at some research in the forum. Unfortunately, it works. I'm not sure which method to use instead of tab.open. Do you have an idea?
Added the cancel:0 property to my AlertDialog.
-
Stefan,
Did you get the eventlistener working? What fixed it, exactly?
For Titanium.UI.Tab, you could try the show() and hide() methods.
-
Hal,
as you guessed in your last post, the problem was at line tab2.open(display,{animated:true}). I made some changes, so that i opened the content in my second window with win2.open(display). After that, the event listener realizes the click event.