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?
1 Answer
-
Added an attribute to the image view named clickname for easy reference
var myImageView = Titanium.UI.createImageView({ image:'img/redCheck.png', width:'auto', height:'auto', clickName:'myClickName', left:4 });
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
tableview.addEventListener('click',function(e)){ if(e.source.clickName == 'myClickName'){ if(e.row.children[0].image == 'image_1.png'){ e.row.children[0].image = 'image_2.png'; } else{ e.row.children[0].image = 'image_2.png'; }; }; };
I am using the image view as a checkbox