Titanium Community Questions & Answer Archive

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

Swapping an imageView within a table row on select

Previously, I used a table row backgroundImage along with a selectedBackgroundImage. I've had to replace the background image with an imageView.

Within the following event listener…

In the tableview.addEventListener('click',function(e))

How do you target the imageView to change the image to a selected one and mimic the effect of selectedBackgroundImage?

— asked March 22nd 2010 by Phi Chong
  • backgroundimage
  • createtableviewrow
  • table

1 Answer

  • Added an attribute to the image view named clickname for easy reference

    var myImageView =  Titanium.UI.createImageView({

    Referencing the child element of the row based on what order you created you row data

        row.add(myImageView);  //children[0]
        row.add(check); //children[1]
        row.add(vendor); //children[2]

    Create your event listener and check for the clickname and access your child element value

        if(e.source.clickName == 'myClickName'){
            if(e.row.children[0].image == 'image_1.png'){
                e.row.children[0].image = 'image_2.png';
                e.row.children[0].image = 'image_2.png';

    I am using the image view as a checkbox

    — answered November 22nd 2010 by Christian Sullivan
    • GREAT explaination of how children are accessed. This helped me tremendously.

      — commented November 3rd 2011 by Seth Davis
    • Agreed. Fantastic explanation, thank you!

      — commented December 15th 2011 by Dooley P
    • This solution is no longer valid in the latest SDK.
      I am no longer able to target .children[0] of a tableviewrow.

      — commented December 26th 2011 by Dooley P
    • Thanks a lot. I was looking for this solution. I wanted to change my ImageView's image when an event was fired from the next screen (UI.Window). It does just that! Amazing and thanks again. :)

      — commented September 26th 2013 by Sufian Babri
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.