Titanium Community Questions & Answer Archive

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

variable or index on dynamic imageView? detect when clicked!

trying to dynamically display thumbnails of images and when clicked, it will bring up a new window showing the full size image.

and this is where the problem lies. how do i detect which imageView ( or regular view ) was clicked? i can't figure out a way to detect that imageView #4 is being clicked instead of imageView #2 and so on.

any help would be greatly appreciated!

rocksteady,
danno~

— asked May 15th 2010 by danno watts
  • dynamic
  • imageview
  • iphone
  • mobile
0 Comments

3 Answers

  • First assign an id/index to that imageview on the list, then use on click event to retrieve the source id/index.

    
    images.addEventListener('singletap', function(e) { 
    var s = e.source;
       alert(s.id) //this is the id or whatever index or url of the image you can recall from singletap event. 
    
    })
    
    — answered May 15th 2010 by Daniel Lim
    permalink
    0 Comments
  • yeah, that's my question, how do i add an id to the imageView?

    thanks!

    rocksteady,
    danno~

    — answered May 16th 2010 by danno watts
    permalink
    0 Comments
  • and i answered my own question:

    var imageView = Titanium.UI.createView({
            backgroundImage:'image.jpg',
            height:50,
            width:50,
            top:10,
            left:10,
            borderWidth:3,
            id:'thisIsMyID',
            borderColor:'#fff'
        });
    

    and to recover that variable, like you said , it's :

    images.addEventListener('singletap', function(e) { 
    var s = e.source;
       alert(s.id)
    })
    

    thanks for the help, i appreciate it!

    rocksteady,
    danno~

    — answered May 16th 2010 by danno watts
    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.