Titanium Community Questions & Answer Archive

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

How to get value of a picker?

How do I get the value of a picker?
I've heard that it's picker.value for a datepicker, but what about a normal picker?

— asked May 28th 2011 by Karanveer Singh
  • android
  • picker
1 Comment
  • You should have a look at the kitchen sink exemples before asking in the Q&A If you can't get your values, you then post your code, so we can help you.

    — commented May 28th 2011 by Luc Martin

6 Answers

  • First of all, you have to define an index or id for each pickerRow like this:

    data[0]=Ti.UI.createPickerRow({id:'0', title:'First row'});
    data[1]=Ti.UI.createPickerRow({id:'1', title:'Second row'});
    data[2]=Ti.UI.createPickerRow({id:'2', title:'Third row'});
    picker.add(data);
    

    In an eventlistener (eg. button click) you can access the id :

    alert(picker.getSelectedRow(0).id);
    
    — answered August 31st 2013 by Zoltan Lengyel
    permalink
    1 Comment
    • Worked thanks :)

      — commented November 21st 2013 by Jean-michel Kromopawiro
  • Hi,U can get the values of the picker row by the following code.on done button click u can get the picker rows selected value.

    done.addEventListener('click',function(e)
    {

    my_combo.value = picker.getSelectedRow(0).title;
    pickerView.animate(slideOut);

    });

    — answered August 1st 2011 by Bhagyashree Shendge
    permalink
    0 Comments
  • Hallo Luc

    try:

    picker.addEventListener('change',function(e) {
        Ti.API.info("You selected row: "+e.row+", column: "+e.column+", custom_item: "+e.row.custom_item);
        label.text = "row index: "+e.rowIndex+", column index: "+e.columnIndex;
    });
    

    Hope it helps

    Rainer

    — answered May 28th 2011 by Rainer Schleevoigt
    permalink
    0 Comments
  • picker.getSelectedRow(0).custom_item < that is your answer

    — answered January 16th 2012 by Tim Hong
    permalink
    1 Comment
    • Thanks. It helped. :)

      Totally surprised why is this question given down votes!

      — commented August 28th 2013 by Sufian Babri
  • How can I get the value without the "change" event listener? I just want to get it with the click of a button, thanks.

    — answered June 9th 2011 by Juan Pablo Enrique
    permalink
    0 Comments
  • Hello,

    I tried the data binding approach as this:

    <Picker id="picker" top="50" useSpinner="true">
                <PickerColumn id="column1" dataCollection="books">
                    <PickerRow title="{name}"/>
                </PickerColumn>
            </Picker>
    

    It works, but I don't know how to retrieve the ID of the selected row. I tried this but didn't work:

    alert($.picker.getSelectedRow(0).id);

    Please help me

    — answered September 10th 2015 by Juan Herrera
    permalink
    0 Comments
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.