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.
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
onclickthat fired off a
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).
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