Hi my event listener on my button (cButton) is not working and i don't understand why this is my code is as follows:
var win1 = Ti.UI.createWindow(); var cButton = Titanium.UI.createButton({ title : 'close', top : 10, width : 50, height : 20 }); cButton.addEventListener('click', function(event) { alert("in eventListener"); win1.close(); }); tableview.addEventListener('click', function(event) { Ti.UI.backgroundColor = 'white'; var image = Ti.UI.createImageView({ image : event.rowData.identifier }); win1.add(cButton); win1.add(image); win1.open(); });Any Ideas?
2 Answers
Accepted Answer
Without a complete minimal case, it's a bit hard to say what's wrong.
I would try restructuring your code so that you construct win1 inside the tableview's click event listener.
tableview.addEventListener('click', function(event) { var win1 = Ti.UI.createWindow({ backgroundColor: '#fff'; ); var cButton = Titanium.UI.createButton({ title : 'close', top : 10, width : 50, height : 20 }); cButton.addEventListener('click', function(event) { alert("in eventListener"); win1.close(); }); var image = Ti.UI.createImageView({ image : event.rowData.identifier }); win1.add(cButton); win1.add(image); win1.open(); });Even better would be to build a custom window class in a CommonJS module and instantiate a new custom window, passing it the image you want to display.
just move where you add the button and image to win1 outside of the tableview event listener and just open win1 from the tableview event listener and it will work.
Your Answer
Think you can help? Login to answer this question!