click event on button not firing
I cannot get this button click event to fire. Any ideas would be greatly appreciated.
var btnnext = Titanium.UI.createButton({title:'++ '});
btnnext.width=25;
btnnext.height=25;
btnnext.left=100;
btnnext.addEventListener('click', function(e)
{
Ti.API.info("testing");
});
winContainer3.add(btnnext);
winContainer2.add(winContainer3);
win2.add(winContainer2);
win2.open();
4 Answers
-
I think the events fires.
Try to use Titanium. instead of Ti. inside the function
Let me know -
Although your not using a ButtonBar here I found that any event on a button in a ButtonBar would not fire at all if the ButtonBar's width was 'auto' setting it to 100% made the buttons suddenly work! There was no discernible visual difference, just another of Titanium's API inconsistencies that keep popping up.
-
I have some issues with my eventListener on a TextField. In my case only focus works. So try:
btnprev.addEventListener('focus', function(){ Ti.API.info('Perhaps focus will work?'); });
-
don't ask me why this works, but it did for me, and it might for you. i had a function
function create_window(){ var button = createButton(....); button.addEventListener(...) var window = createWindow(....); window.add(button); }
the click wasn't firing. but when i did this:
var button = createButton(...); button.addEventListener(...); function create_window(){ var window = createWindow(....); window.add(button); }
i'm sure it's got something to do with the contexts and scopes which i have yet to understand completely in titanium, but it works the first way in one of my scripts but only the second way in another script.
try it on yours - good luck!