Search code examples
javascripttitaniumappceleratortitanium-mobileappcelerator-mobile

Titanium.App.addEventListener not fired, never


app.js

var win1 = Titanium.UI.createWindow({
    title:'Tab 1',
    backgroundColor: 'black',
    layout: 'vertical',

});

win1.open();

Titanium.App.addEventListener('click', function(e) {
    console.log('clicked');
});

If I tap/click on the screen, the click event doesn't fire! Do you know why? All my code is that above on app.js

EDIT

  • If I would listen for a "swipe" event, how I would to do?

  • Why I don't see errors or warning in my debug console for this?


Solution

  • The "click" event is fired on the object that is clicked, namely, win1. So is "swipe". Please read the documentation to learn what events are available.

    var win1 = Ti.UI.createWindow({
        title:'Tab 1',
        backgroundColor: 'black',
        layout: 'vertical'
    });
    win1.addEventListener('click', function(e) {
        Ti.API.info('clicked');
    });
    win1.addEventListener('swipe', function(e) {
        Ti.API.info('swiped');
    });
    win1.open();
    

    Your code is valid, so no errors or warnings are displayed. But it does not do what you expect. Please read the documentation on the standard events that fire on Titanium.App, and on the custom events that you can fire on Titanium.App. Also read the documentation on Titanium.UI.View to understand what standard events are fired.