Titanium Community Questions & Answer Archive

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

Get index of clicked tableRow

Hi,

i want to get the index of my clicked row (e.g. my picker contains 20 rows, i want to know which one i clicked).

I tried it like this:

cityPicker.addEventListener('change',
function(e) {
Ti.API.info(e.index);

if (e.index >= 7){
        searchCity    = e.row.id;
    }
)};

My output of the API.info is <null>.

Someone who can help me?

— asked August 12th 2010 by Michael Gajda
  • click
  • event
  • index
  • iphone
  • picker
1 Comment
  • See if this helps:
    http://appcelerated.wikispot.org/TableViewRows

    — commented August 12th 2010 by Alan Bourke

4 Answers

  • Can you post more of your code, are you using multiple columns?

    — answered August 12th 2010 by Conrad Fuhrman
    permalink
    0 Comments
  • Sure ;)

    My picker:

    var cityPicker = Titanium.UI.createPicker({
        selectionIndicator: true,
        type: Titanium.UI.PICKER_TYPE_PLAIN,
        top: 40
    });
    

    My array :

    ...
    cityData[7] = Titanium.UI.createPickerRow({
        title: 'FooTown',
        id: 48
    });
    cityData[8] = Titanium.UI.createPickerRow({
        title: 'Bar-City',
        id: 3
    });
    ...
    

    And i add the Data via:

    cityPicker.add(cityData);
    
    — answered August 12th 2010 by Michael Gajda
    permalink
    0 Comments
  • Ah, i got it:

    e.index
    

    is wrong…
    i have to use

    e.rowIndex
    
    — answered August 13th 2010 by Michael Gajda
    permalink
    0 Comments
  • Ah, i got it:

    e.index
    

    is wrong…
    i have to use

    e.rowIndex
    
    — answered August 13th 2010 by Michael Gajda
    permalink
    2 Comments
    • I know this is 2 years later and many things have changed, but on SDK 2.3.1 e.index is valid. But better still is tableView.getIndexByName('rowName'); where 'rowname' is any property you can assign uniquely to a row. If you are looping, it could be a number as well. Something like:

      row - Ti.UI.createTableViewRow({
      name:'row1'
      )}
      
      tableView.getIndexByName('row1');
      

      — commented January 17th 2013 by Shalvika Sood
    • Forgot to add that this works only on IOS

      — commented January 17th 2013 by Shalvika Sood
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.