Wheel picker itemChanged Event

Hi all,

Just wondering how I can get the selected value of a wheelpicker when a user has selected a row and the value has changed.

Currently I have a wheel picker in a newGroup and when a user clicks a button I make the wheel picker appear and when a user taps a value I call the onValueSelected event which within my code block hides the wheel picker but how can I get the actual value of the row that was picked within this event?

Can I do something like this: 

onValueSelected =function(event) and the event contains the selected index? My Wheel picker only has one column.

I did a quick modification of the WidgetDemo sample app in SampleCode/Interface/WidgetDemo to make the pickerWheel use the onValueSelected event.  Look at this example:

 -- Set up the picker column data local months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } local days = {} local years = {} for i = 1,31 do days[i] = i end for j = 1,47 do years[j] = 1969+j end local columnData = { { align = "right", width = 125, startIndex = 5, labels = months, }, { align = "center", width = 70, startIndex = 18, labels = days, }, { align = "center", width = 65, startIndex = 21, labels = years, }, } local json = require("json") local function fetchValues( event ) print( json.prettify( event ) ) if event.column == 1 then print("Month:", months[event.row]) elseif event.column == 2 then print("Day:", days[event.row]) else print("Year:", years[event.row]) end end -- Create a new Picker Wheel local pickerWheel = widget.newPickerWheel { top = display.contentHeight-222-tabBarHeight-20+oy, columns = columnData, onValueSelected = fetchValues } pickerWheel.x = display.contentCenterX sceneGroup:insert( pickerWheel )

Rob

1 Like

fab, this works well.

I did a quick modification of the WidgetDemo sample app in SampleCode/Interface/WidgetDemo to make the pickerWheel use the onValueSelected event.  Look at this example:

 -- Set up the picker column data local months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } local days = {} local years = {} for i = 1,31 do days[i] = i end for j = 1,47 do years[j] = 1969+j end local columnData = { { align = "right", width = 125, startIndex = 5, labels = months, }, { align = "center", width = 70, startIndex = 18, labels = days, }, { align = "center", width = 65, startIndex = 21, labels = years, }, } local json = require("json") local function fetchValues( event ) print( json.prettify( event ) ) if event.column == 1 then print("Month:", months[event.row]) elseif event.column == 2 then print("Day:", days[event.row]) else print("Year:", years[event.row]) end end -- Create a new Picker Wheel local pickerWheel = widget.newPickerWheel { top = display.contentHeight-222-tabBarHeight-20+oy, columns = columnData, onValueSelected = fetchValues } pickerWheel.x = display.contentCenterX sceneGroup:insert( pickerWheel )

Rob

fab, this works well.