Titanium Community Questions & Answer Archive

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

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;
});
— asked August 12th 2010 by Simon Kok
  • picker multi column
1 Comment
  • I figured it out. Look at the KitchenSink demo a bit more closely…

    e.columnIndex is my friend. :)

    serverConfigurationPicker.addEventListener('change',function(e)
    {
        Ti.API.info("You selected row: " + e.row.custom_item);
    
        if (e.columnIndex == 0){
            label1.text = "CPU : " +e.row.custom_item;
        } else {
            label2.text = "Memory: " +e.row.custom_item;
        }
    });
    
    — commented August 13th 2010 by Simon Kok

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.

    — answered December 11th 2011 by Aizil Akmar Omar
    permalink
    1 Comment
    • problem settled using simon's code.

      — commented December 17th 2011 by Aizil Akmar Omar
  • 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]);
    
    });
    
    — answered September 3rd 2012 by Sarafaraz Babi
    permalink
    1 Comment
    • Thank you and keep contributing.. :)

      — commented September 3rd 2012 by Aizil Akmar Omar
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.