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?
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);
-
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);});
-
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
-
picker.getSelectedRow(0).custom_item < that is your answer
-
How can I get the value without the "change" event listener? I just want to get it with the click of a button, thanks.
-
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