Android - Simple listener function problem

You must Login before you can answer or comment on any questions.

Hi guys, I'm having a bit of a problem. I've got 9 image views (img1, img2, img3, etc) and I want to add a click event listener to all of them.

I've tried saving the function as a variable but somehow the e isn't associated with the imageview.

example code:

var img1 = Ti.UI.createImageView({
            image:"sample.jpg"
        });
 
var listenerFunc = function(e){
    Ti.API.info(e.image);
};
 
img1.addEventListener('click',listenerFunc);
The result of the above will be undefined.

Any ideas guys?

1 Answer

Accepted Answer

If you test your code with:

img1.addEventListener('click',(e){
    Ti.API.log(e);
});
you will see the content of e. The right property is source.

— answered 1 year ago by Rainer Schleevoigt
answer permalink
1 Comment
  • Yeap, e.source.image did the trick. Thanks for your help friend.

    At a logical view, didn't e supposed to have been associated with the image view ?

    — commented 1 year ago by ariel baruch

Your Answer

Think you can help? Login to answer this question!