Picker Wheel print to label on change

I am trying to update a label to currently selected value in a picker wheel but can only get it to print when app launches. How can I set it up so I can check if row has changed and update a label? Basically I want to be able to scroll through Picker Wheel and when I select a different value it automatically updates the label 

See:  https://docs.coronalabs.com/api/library/widget/newPickerWheel.html

There is an option “onValueSelected” that lets you define a function that gets called when the picker wheel value changes. Inside that function, you can update your label.

Rob

could you please give me an example of it being used I tried this and it didn’t work 

[lua]-- Create the widget
local pickerWheel = widget.newPickerWheel(
{
–x = display.contentCenterX,
top = display.contentHeight - 158,
columns = columnData,
style = “resizable”,
width = display.contentWidth,
rowHeight = 30,
height=10,

–height = display.viewableContentHeight,
borderPadding =0,

–rowHeight = 32,
–fontSize = 14
})

pickerWheel.x = display.contentCenterX
Runtime:addEventListener( “onValueSelected”, setButtonLabel )
– Get the table of current values for all columns
– This can be performed on a button tap, timer execution, or other event
local values = pickerWheel:getValues()

– Get the value for each column in the wheel, by column index
local currentStyle = values[1].value
pickerWheel.alpha=0

print(currentStyle)[/lua]

[lua]-- – Function to handle button events
local function setButtonLabel( event )

if ( “ended” == event.phase ) then
print( “change” )
local values = pickerWheel:getValues()
print(values[1].value)

end
end[/lua]

-- Create the widget local pickerWheel = widget.newPickerWheel( { --x = display.contentCenterX, top = display.contentHeight - 158, columns = columnData, style = "resizable", width = display.contentWidth, rowHeight = 30, height=10, --height = display.viewableContentHeight, borderPadding =0, --rowHeight = 32, --fontSize = 14, onValueSelected = setButtonLabel, }) pickerWheel.x = display.contentCenterX -- Get the table of current values for all columns -- This can be performed on a button tap, timer execution, or other event local values = pickerWheel:getValues() -- Get the value for each column in the wheel, by column index local currentStyle = values[1].value pickerWheel.alpha=0 print(currentStyle)

You define the function as part of the pickerWheel constructor and not as a listener you add to an object.  You do have to create/define your setButtonLabel() function before you create the pickerWheel object.

Rob

See:  https://docs.coronalabs.com/api/library/widget/newPickerWheel.html

There is an option “onValueSelected” that lets you define a function that gets called when the picker wheel value changes. Inside that function, you can update your label.

Rob

could you please give me an example of it being used I tried this and it didn’t work 

[lua]-- Create the widget
local pickerWheel = widget.newPickerWheel(
{
–x = display.contentCenterX,
top = display.contentHeight - 158,
columns = columnData,
style = “resizable”,
width = display.contentWidth,
rowHeight = 30,
height=10,

–height = display.viewableContentHeight,
borderPadding =0,

–rowHeight = 32,
–fontSize = 14
})

pickerWheel.x = display.contentCenterX
Runtime:addEventListener( “onValueSelected”, setButtonLabel )
– Get the table of current values for all columns
– This can be performed on a button tap, timer execution, or other event
local values = pickerWheel:getValues()

– Get the value for each column in the wheel, by column index
local currentStyle = values[1].value
pickerWheel.alpha=0

print(currentStyle)[/lua]

[lua]-- – Function to handle button events
local function setButtonLabel( event )

if ( “ended” == event.phase ) then
print( “change” )
local values = pickerWheel:getValues()
print(values[1].value)

end
end[/lua]

-- Create the widget local pickerWheel = widget.newPickerWheel( { --x = display.contentCenterX, top = display.contentHeight - 158, columns = columnData, style = "resizable", width = display.contentWidth, rowHeight = 30, height=10, --height = display.viewableContentHeight, borderPadding =0, --rowHeight = 32, --fontSize = 14, onValueSelected = setButtonLabel, }) pickerWheel.x = display.contentCenterX -- Get the table of current values for all columns -- This can be performed on a button tap, timer execution, or other event local values = pickerWheel:getValues() -- Get the value for each column in the wheel, by column index local currentStyle = values[1].value pickerWheel.alpha=0 print(currentStyle)

You define the function as part of the pickerWheel constructor and not as a listener you add to an object.  You do have to create/define your setButtonLabel() function before you create the pickerWheel object.

Rob