Noob Question about Radio Button

Hi,

I have a rather dumb question about radiobutton in widget.newSwitch.

I say “dumb” because it is a really elementary and rudimentary question.

So I want to store the particular button the user chose, so that later, when the user returns to the scene, the button the user last chose will be selected. Simple enough right?

Here is the documentation for radio button:
https://docs.coronalabs.com/api/library/widget/newSwitch.html

According to the documentation, I have available the method Object:setState( )

However, when I do something like

myRadioButton:setState{isOn = true}

nothing happens!

Oddly enough, when I do the same thing to an onOff button, such as

myOnOffButton:setState{isOn = true}

it works!!

Am I missing something here? Clearly, I am missing something very obvious??

Thanks in advance!
KC

It works in an app that I’ve built. Here’s my code:

scene:create()

 distanceLabel = display.newText( "Distance Settings", display.contentCenterX, 105, native.systemFontBold) scrollView:insert( distanceLabel ) local unitsRadioGroup = display.newGroup() scrollView:insert( unitsRadioGroup ) milesButton = widget.newSwitch { left = 20, top = distanceLabel.y + 30, style = "radio", id = "miles", onPress = onRadioButtonPress } unitsRadioGroup:insert( milesButton ) milesText = display.newText( "Miles", 60, milesButton.y, native.systemFont, 18 ) milesText.anchorX = 0 scrollView:insert( milesText ) kilometersButton = widget.newSwitch { left = 20, top = milesButton.y + 30, style = "radio", id = "kilometers", onPress = onRadioButtonPress } unitsRadioGroup:insert( kilometersButton ) kiloText = display.newText( "Kilometers", 60, kilometersButton.y, native.systemFont, 18 ) kiloText.anchorX = 0 scrollView:insert( kiloText )

then in my scene:show()

 if myData.settings.distanceUnits == "miles" then milesButton:setState( { isOn = true } ) else kilometersButton:setState( { isOn = true } ) end

In Lua if the only parameter passed to a function is a table you don’t need the parenthesis, but I like to include them to remind me I’m calling a function.

It works in an app that I’ve built. Here’s my code:

scene:create()

 distanceLabel = display.newText( "Distance Settings", display.contentCenterX, 105, native.systemFontBold) scrollView:insert( distanceLabel ) local unitsRadioGroup = display.newGroup() scrollView:insert( unitsRadioGroup ) milesButton = widget.newSwitch { left = 20, top = distanceLabel.y + 30, style = "radio", id = "miles", onPress = onRadioButtonPress } unitsRadioGroup:insert( milesButton ) milesText = display.newText( "Miles", 60, milesButton.y, native.systemFont, 18 ) milesText.anchorX = 0 scrollView:insert( milesText ) kilometersButton = widget.newSwitch { left = 20, top = milesButton.y + 30, style = "radio", id = "kilometers", onPress = onRadioButtonPress } unitsRadioGroup:insert( kilometersButton ) kiloText = display.newText( "Kilometers", 60, kilometersButton.y, native.systemFont, 18 ) kiloText.anchorX = 0 scrollView:insert( kiloText )

then in my scene:show()

 if myData.settings.distanceUnits == "miles" then milesButton:setState( { isOn = true } ) else kilometersButton:setState( { isOn = true } ) end

In Lua if the only parameter passed to a function is a table you don’t need the parenthesis, but I like to include them to remind me I’m calling a function.