Appcelerator Blog

The Leading Resource for All Things Mobile

Titanium Quickie: Toggling Object In A TableViewRow

0 Flares 0 Flares ×
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. tableRow.children[0] 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:
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

5 Comments

  1. Shawn

    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. Aaron Saunders

    @Shawn yes is does work for most of the other objects, and yes it will give you the tableRow object

  3. This doesn’t seem to work any longer.
    .children simply returns undefined from a tableview row.

  4. Kevin Whinnery

    @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.

  5. Rich

    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.

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×