Picker and math
Hi all
Anyone who can help me with this:
I have a double picker with some different numbers in them.
Under that i have a label.
How can i do it so that the label will show this:
(0,5*left_picker*right_picker)/600
It is for the iPhone
Thank you very much
11 Answers
-
Dennis
I don't understand what you are using the comma for. Do you mean 0.5?
What values do left_picker and right_picker contain?
Do you want ((0.5 left_picker right_picker)/600) ?
-
Hi Hal
I am from Denmark where we use , instead of .
Sorry about that. Left contains the numbers: 3,4,5,6,7,8,9,10,12,15,20 and right contains: 25,50,75,100,125,150,175,200,250,300,350,400,450,500,550,600
-
Anybody who can help?
-
Dennis, I think you have 2 columns in the picker, that you named left_picker and right_picker
In this case you can use the change event to take the selectedValue that in your case will be an array with 2 elements ( at least this is what I know).Makes sense?
-
Makes perfect sense, I just cannot figure out how to do this…
-
the_picker.addEvent('change', function(e) { the_label.text = (0.5*e.selectedValue[0]*e.selecteValue[1])/600; })
it works?
-
ups
the_label.text = ...
not value
-
hmm no it makes an error in line 88, saying picker.addevent is not a function.
Dennis
// this sets the background color of the master UIView (when there are no windows/tab groups on it) Titanium.UI.setBackgroundColor('#000'); // create tab group var tabGroup = Titanium.UI.createTabGroup(); // // create base UI tab and root window // var win = Titanium.UI.createWindow({ title:'Calculate l/min', backgroundColor:'black', }); var pickerview = Titanium.UI.createView({ top:-159, }); var picker = Ti.UI.createPicker(); var speed = Ti.UI.createPickerColumn({opacity:0}); speed.addRow(Ti.UI.createPickerRow({title:'Speed km/h', selected:true})); speed.addRow(Ti.UI.createPickerRow({title:'3',custom_item:'3'})); speed.addRow(Ti.UI.createPickerRow({title:'4',custom_item:'4'})); speed.addRow(Ti.UI.createPickerRow({title:'5',custom_item:'5'})); speed.addRow(Ti.UI.createPickerRow({title:'6',custom_item:'6'})); speed.addRow(Ti.UI.createPickerRow({title:'7',custom_item:'7'})); speed.addRow(Ti.UI.createPickerRow({title:'8',custom_item:'8'})); speed.addRow(Ti.UI.createPickerRow({title:'9',custom_item:'9'})); speed.addRow(Ti.UI.createPickerRow({title:'10',custom_item:'10'})); speed.addRow(Ti.UI.createPickerRow({title:'12',custom_item:'12'})); speed.addRow(Ti.UI.createPickerRow({title:'15',custom_item:'15'})); speed.addRow(Ti.UI.createPickerRow({title:'20',custom_item:'20'})); var volume = Ti.UI.createPickerColumn(); volume.addRow(Ti.UI.createPickerRow({title:'Volume l/ha', selected:true})); volume.addRow(Ti.UI.createPickerRow({title:'25',custom_item:'25'})); volume.addRow(Ti.UI.createPickerRow({title:'50',custom_item:'50'})); volume.addRow(Ti.UI.createPickerRow({title:'75',custom_item:'75'})); volume.addRow(Ti.UI.createPickerRow({title:'100',custom_item:'100'})); volume.addRow(Ti.UI.createPickerRow({title:'125',custom_item:'125'})); volume.addRow(Ti.UI.createPickerRow({title:'150',custom_item:'150'})); volume.addRow(Ti.UI.createPickerRow({title:'175',custom_item:'175'})); volume.addRow(Ti.UI.createPickerRow({title:'200',custom_item:'200'})); volume.addRow(Ti.UI.createPickerRow({title:'250',custom_item:'250'})); volume.addRow(Ti.UI.createPickerRow({title:'300',custom_item:'300'})); volume.addRow(Ti.UI.createPickerRow({title:'350',custom_item:'350'})); volume.addRow(Ti.UI.createPickerRow({title:'400',custom_item:'400'})); volume.addRow(Ti.UI.createPickerRow({title:'450',custom_item:'450'})); volume.addRow(Ti.UI.createPickerRow({title:'500',custom_item:'500'})); volume.addRow(Ti.UI.createPickerRow({title:'550',custom_item:'550'})); volume.addRow(Ti.UI.createPickerRow({title:'600',custom_item:'600'})); // 2 columns as an array picker.add([speed,volume]); // turn on the selection indicator (off by default) picker.selectionIndicator = true; pickerview.add(picker); var label = Ti.UI.createLabel({ text:'l/min.', top:400, width:'auto', height:'auto', textAlign:'left', color:'white', left:10, }); picker.addEvent('change', function(e) { label.text = (0.5*e.selectedValue[0]*e.selecteValue[1])/600; }) pickerview.add(label); win.add(pickerview); var tab1 = Titanium.UI.createTab({ icon:'KS_nav_views.png', title:'l/min', window:win }); // // create controls tab and root window // var win2 = Titanium.UI.createWindow({ title:'Tab 2', backgroundColor:'#fff' }); var tab2 = Titanium.UI.createTab({ icon:'KS_nav_ui.png', title:'Tab 2', window:win2 }); var label2 = Titanium.UI.createLabel({ color:'#999', text:'I am Window 2', font:{fontSize:20,fontFamily:'Helvetica Neue'}, textAlign:'center', width:'auto' }); win2.add(label2); // // add tabs // tabGroup.addTab(tab1); tabGroup.addTab(tab2); // open tab group tabGroup.open();
-
addEventListener not addEvent, sorry
-
Got it to work! But how do I add some text behind the result? eg. "l/min"
And how do I limit the digits to x.xx ??
-
label.text = ((0.5*e.selectedValue[0]*e.selecteValue[1])/600).toFixed(2)+'l/min';
This is pure javascript, has nothing with Appcelerator, maybe you'd like to take a deeper look at the JS documentation :)