Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

A matrix of dynamic imageViews, wich one was clicked?

For an image gallery I am trying to build a matrix of images from an array of image names by stepping through the array and creating an image View (of the same name) on every iteration. That works so far.

I am too attaching an event listener on each iteration. Here is where the problem begins. Because all imageViews are named the same (bc created in a for-construct) the event listener gets confused on what actual image the user clicked.

I think of using dynamic variable names but I am not sure if that is the best way to go. Maybe one of the more experienced users know a better way to implement it.

I am glad for every hint - I do not necessarily need working code.

— asked May 4th 2010 by Christian Victor
  • dynamic
  • event
  • imageview
  • listener
  • mobile
  • variables
0 Comments

2 Answers

  • I did something similar and found that with the 170 images I was using, it was just too slow.

    I ended up creating a WebView with the images and each image had an onclick that fired off a Ti.App.fireEvent()

    So, I don't know if that would work for your use case, but it was much faster for me than creating 170 imageViews each with an eventListener.

    However, to answer your specific question, when I did create separate imageViews, I did it by putting them in a list. Seemed like a cleaner variable namespace to me and it was then something I could iterate over if needed (like, creating event listeners after the imageViews display, etc).

    — answered May 4th 2010 by Jackson Miller
    permalink
    0 Comments
  • In the click or even the touch events there is a source property that has a reference to the object that was touched or clicked.

    so like in a click event would be like this
    function(e){
    Ti.API.log(e.source);
    }

    — answered May 4th 2010 by Clint Tredway
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.