Quantcast
Viewing all articles
Browse latest Browse all 8068

How to setSelectedRow of Picker only by Value (or Title)

I want to choose which row of the Picker to select based on its value ("title"). Let's say I just queried the database and the record I opened has a value of 'Youth', which is one of the options in the Picker. How can I set the Picker to the row with the Value/Title of 'Youth'?

This is easy when I have the data[] for the Picker rows (code below).

data[0]=Ti.UI.createPickerRow({title:'High School'});
data[1]=Ti.UI.createPickerRow({title:'College'});
data[2]=Ti.UI.createPickerRow({title:'Professional'});
data[3]=Ti.UI.createPickerRow({title:'Youth'});
 
var selectedRow = 0;
var pickValue = 'Youth';
 
for(var i = 0; i < data.length; i++)
{
    if(data[i].title == pickValue)
    {
        selectedRow = i;
        break;
    }
}
 
picker.setSelectedRow(0, selectedRow, false);
But what if I don't? How can I loop through the different Title or Value fields of a Picker to find the proper index?

Titanium Studio, build: 3.1.3.201309132423 Titanium SDK 3.1.3.GA

I already have a solution for iOS (the code above). I am looking for a solution for Android.


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>