Help with Getting Multi Picker Values
Hi there.
How do I get the values for my CPU and MEMORY values selected from my picker? It's only displaying the one value selected.
See example below:
var win = Titanium.UI.currentWindow;
win.backgroundColor = 'black';
var serverConfigurationPicker = Ti.UI.createPicker();
var cpuColumn = Ti.UI.createPickerColumn({opacity:0});
cpuColumn.addRow(Ti.UI.createPickerRow({title:'1 CPU',custom_item:'1 CPU'}));
cpuColumn.addRow(Ti.UI.createPickerRow({title:'2 CPU',custom_item:'2 CPU'}));
cpuColumn.addRow(Ti.UI.createPickerRow({title:'3 CPU',custom_item:'3 CPU'}));
cpuColumn.addRow(Ti.UI.createPickerRow({title:'4 CPU',custom_item:'4 CPU'}));
var memoryColumn = Ti.UI.createPickerColumn();
memoryColumn.addRow(Ti.UI.createPickerRow({title:'1 GB',custom_item:'1 GB'}));
memoryColumn.addRow(Ti.UI.createPickerRow({title:'2 GB',custom_item:'2 GB'}));
memoryColumn.addRow(Ti.UI.createPickerRow({title:'3 GB',custom_item:'3 GB'}));
memoryColumn.addRow(Ti.UI.createPickerRow({title:'4 GB',custom_item:'4 GB'}));
// 2 columns as an array
serverConfigurationPicker.add([cpuColumn,memoryColumn]);
// turn on the selection indicator (off by default)
serverConfigurationPicker.selectionIndicator = true;
win.add(serverConfigurationPicker);
var label = Ti.UI.createLabel({
text:'Select CPU & Memory Configuration',
top:0,
width:'auto',
height:'auto',
textAlign:'center',
color:'white'
});
win.add(label);
var label1 = Ti.UI.createLabel({
text:'',
top:20,
width:'auto',
height:'auto',
textAlign:'center',
color:'white'
});
win.add(label1);
var label2 = Ti.UI.createLabel({
text:'',
top:40,
width:'auto',
height:'auto',
textAlign:'center',
color:'white'
});
win.add(label2);
serverConfigurationPicker.addEventListener('change',function(e)
{
label1.text = "CPU Selected: " +e.row.custom_item;
label2.text = "Memory Selected: " +e.row.custom_item;
});
2 Answers
-
How to get both values at the same time? e.g 2CPU, 4GB?
For my case, i always get undefined for the first column when i selected the 2nd column.
-
Hello everyone,
I know it's too late answer of this question but still i am answering b'coz it could be help other who are facing this type of problem…
I have made one picker like time picker that gets value from 3 column…
Here is the pickerview.js file code…
Ti.UI.backgroundColor = 'white'; var win = Ti.UI.currentWindow; var picker = Ti.UI.createPicker({ top:50 }); picker.selectionIndicator = true; var Hours = []; var Minits = []; Ti.App.Hours = 0; Ti.App.Minit = 0; Ti.App.Second = 0; for(var i = 0; i < 24 ; i++){ var str = ''; if(i < 10){ str = '0'+i; }else{ str = ''+i; } Hours.push(str); } for(var i = 0; i < 60 ; i++){ var str = ''; if(i < 10){ str = '0'+i; }else{ str = ''+i; } Minits.push(str); } var column1 = Ti.UI.createPickerColumn(); for(var i=0 ; i < Hours.length; i++){ var row = Ti.UI.createPickerRow({ title: Hours[i] }); column1.addRow(row); } var column2 = Ti.UI.createPickerColumn(); for(var i=0 ; i <Minits.length; i++){ var row = Ti.UI.createPickerRow({ title: Minits[i] }); column2.addRow(row); } var column3 = Ti.UI.createPickerColumn(); for(var i=0 ; i <Minits.length; i++){ var row = Ti.UI.createPickerRow({ title: Minits[i] }); column3.addRow(row); } picker.add([column1,column2,column3]); win.add(picker); var lable = Ti.UI.createLabel({ top : 10, height : 30, width : 150, backgroundColor : 'red' }); win.add(lable); picker.addEventListener('change',function(e){ Ti.API.info("You selected row: " + e.row.custom_item); if(e.columnIndex == 0){ Ti.App.Hours = e.rowIndex; }else if(e.columnIndex == 1){ Ti.App.Minit = e.rowIndex; }else{ Ti.App.Second = e.rowIndex; } alert(Hours[Ti.App.Hours] +":" +Minits[Ti.App.Minit] + ":" +Minits[Ti.App.Second]); });