Based on the documentation [http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Picker], the object Ti.Ui:Picker as a method to set the colums called
Ti.UI.Picker.setColumns();which recieve an array Ti.UI.PickerRow object as argument, or a single Ti.UI.pickerRow
So, to clear out the picker options, if I try
var pInput = Ti.UI.createPicker({ }); var data = []; data[0]=Ti.UI.createPickerRow({title:'Tdata1'}); data[1]=Ti.UI.createPickerRow({title:'Tdata2'}); data[2]=Ti.UI.createPickerRow({title:'Tdata3'}); data[3]=Ti.UI.createPickerRow({title:'Tdata4'}); pInput.add(data); /** * data should be an array of Ti.UI.PickerRow **/ var setPInput = function (data){ pInput.setColumns(null); pInput.add(data); };You get an uncaugth exception:
ERROR][TiJSError( 1966)] (main) [1,20823] - Message: Uncaught Error: Java Exception occurred [ERROR][TiJSError( 1966)] (main) [1,20824] - Source: pInput.setColumns(null);;So, I changed to pass an TI.UI.PickerRow as argument doing
var setPInput = function (data){ pInput.setColumns(Ti.UI.createPickerRow({title:'Bananas'})); pInput.add(data); };I got the colums cleared, but no "bananas" option, and the following warning
[WARN][PickerProxy( 2098)] Unexpected object type ignored for setColumnsSince I got this error, then I created and array and passed the array...
var setPInput = function (data){ var bananas = []; bananas[0]=Ti.UI.createPickerRow({title:'Bananas'}) pInput.setColumns(bananas); pInput.add(data); };again, got the columns cleared, no "bananas", and the same warning
[WARN][PickerProxy( 2098)] Unexpected object type ignored for setColumnsSo, what would be the correct way to clear the columns? and what would be the correct parameter type to pass to setColumns?
1 Answer
Accepted Answer
Hi, Try this way:
var win = Ti.UI.createWindow({ layout: 'vertical' }); var picker = Ti.UI.createPicker({ top:50 }); picker.selectionIndicator = true; var fruit = [ 'Bananas', 'Strawberries', 'Mangos', 'Grapes' ]; var color = [ 'red', 'green', 'blue', 'orange' ]; var column1 = Ti.UI.createPickerColumn(); for(var i=0, ilen=fruit.length; i<ilen; i++){ var row = Ti.UI.createPickerRow({ title: fruit[i] }); column1.addRow(row); } var column2 = Ti.UI.createPickerColumn(); for(var i=0, ilen=color.length; i<ilen; i++){ var row = Ti.UI.createPickerRow({ title: color[i] }); column2.addRow(row); } picker.add([column1,column2]); win.add(picker); win.open();
its a demo code for help.. modify as per your need.
Your Answer
Think you can help? Login to answer this question!