Titanium Quickie: Toggling Object In A TableViewRow

Two photographs of colored pencils and a paint brush combined to form a new object.

Editors Note: This technique will work only in Titanium Mobile 1.7.x. This article was cross-posted with permission from Aaron Saunders at Clearly Innovative.

So, the basic problem is that we have a checkBox, switch, button or any object that we need to capture the click event for and keep some state information about that object. I want to be able to click the object, save its state and not impact the rest of the items in the row.

I also need a way to find out which items are selected, since multiple items could be selected and it is the object that is selected not the row.

The first example is pretty straight forward, but then there are additional methods that I have added as a possible way to solve additional problems that come up when working with tables and objects in rows

In the table above, we are able to find the child elements because we know where we put it; also there is only one element.


If there are multiple elements, one solution is to provide ids and then use a function like the one below to iterate through the child objects and find the one you are looking for.

Another thing that might come in handy is a method for finding which elements are selected

Final Solution with helpers included to show more fun stuff:


  1. evt.source.parent … hmmmm…where is that documented? Does every view have a .parent? Does every visual object have a .parent?

    I’m assuming evt.source.parent gives you the TableViewRow that the object was .add()ed to, right? Does this work for other containers, besides TableViewRows?

  2. @Dooley, yes, this particular tutorial used an API that was undocumented (.children)- this was removed in Android in 1.8.x and should not be used on that and future versions until .children becomes a supported interface.

  3. I used .children extensively in my application. With it now missing in 1.8.x what are others doing to iterate various objects added to a tableViewRow? My UI requires various imageviews, labels, etc. on the row and knowing which was selected by the user.

Comments are closed.