How to do a multiple group of radiobutton? I did, but switchState error after click one of the button.

How to do a multiple group of radiobutton? I did, at first the initialSwitchState work fine, different group have their own (only one radiobutton) “true” state. However when I click one of radiobutton (in any group), all of the switchState from all of the group was disappear and only appear on the button that I clicked.  Why? is this bug?

first I do this:

-- Create a group for the radio button set local radioTheme = display.newGroup()

and each of the button of the group have this:

 radioTheme:insert( radioButtonTheme1 )

So, I thought there is no way the other group will interfere another radio group button. But, in fact it didn’t go that way… please help sir! thx!

Can you paste more code including where you’re creating the radio buttons?

Thanks

Rob

local function onSwitchPressTheme( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) myData.settings.theme = switch.id utility.saveTable(myData.settings, "settings.json") end local function onSwitchPress( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) myData.settings.language = switch.id utility.saveTable(myData.settings, "settings.json") end -- Create a group for the radio button set local radioTheme = display.newGroup() local sampleTheme1 = display.newImage("tmbsample.png", 65, soundLabel.y + 35) sampleTheme1.width=35 sampleTheme1.height=35 sceneGroup:insert( sampleTheme1 ) local sampleTheme2 = display.newImage("tmbt2sample.png", 65, soundLabel.y + 75) sampleTheme2.width=35 sampleTheme2.height=35 sceneGroup:insert( sampleTheme2 ) -- Create two associated radio buttons (inserted into the same display group) local radioButtonTheme1 = widget.newSwitch { left = 15, top = soundLabel.y + 20, style = "radio", id = 1, onPress = onSwitchPressTheme, initialSwitchState = themeSaatIni[1], } radioTheme:insert( radioButtonTheme1 ) local radioButtonTheme2 = widget.newSwitch { left = 15, top = soundLabel.y + 60, style = "radio", id = 2, onPress = onSwitchPressTheme, initialSwitchState = themeSaatIni[2], } radioTheme:insert( radioButtonTheme2 ) sceneGroup:insert( radioButtonTheme1 ) sceneGroup:insert( radioButtonTheme2 ) -- Create a group for the radio button set local radioGroup = display.newGroup() -- Create two associated radio buttons (inserted into the same display group) local radioButton1 = widget.newSwitch { left = 100, top = languageLabel.y + 20, style = "radio", id = "en", onPress = onSwitchPress, initialSwitchState = languageSaatIni[1], } radioGroup:insert( radioButton1 ) local radioButton2 = widget.newSwitch { left = 100, top = languageLabel.y + 60, style = "radio", id = "id", onPress = onSwitchPress, initialSwitchState = languageSaatIni[2], } radioGroup:insert( radioButton2 ) sceneGroup:insert( radioButton1 ) sceneGroup:insert( radioButton2 )

It’s clear that I have each group buttons separated from each other. Am I wrong?

Display objects can only be in one group at a time. Even though  you insert the radio button into the radio button group, when you later add the radio button to the sceneGroup, you’re in effect taking it out of the radioButton group. The solution is to only put the radio buttons into the radio button group, then insert the radio button group into sceneGroup instead of the individual buttons

Rob

Woah, I see. I’ll try.

Can you paste more code including where you’re creating the radio buttons?

Thanks

Rob

local function onSwitchPressTheme( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) myData.settings.theme = switch.id utility.saveTable(myData.settings, "settings.json") end local function onSwitchPress( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) myData.settings.language = switch.id utility.saveTable(myData.settings, "settings.json") end -- Create a group for the radio button set local radioTheme = display.newGroup() local sampleTheme1 = display.newImage("tmbsample.png", 65, soundLabel.y + 35) sampleTheme1.width=35 sampleTheme1.height=35 sceneGroup:insert( sampleTheme1 ) local sampleTheme2 = display.newImage("tmbt2sample.png", 65, soundLabel.y + 75) sampleTheme2.width=35 sampleTheme2.height=35 sceneGroup:insert( sampleTheme2 ) -- Create two associated radio buttons (inserted into the same display group) local radioButtonTheme1 = widget.newSwitch { left = 15, top = soundLabel.y + 20, style = "radio", id = 1, onPress = onSwitchPressTheme, initialSwitchState = themeSaatIni[1], } radioTheme:insert( radioButtonTheme1 ) local radioButtonTheme2 = widget.newSwitch { left = 15, top = soundLabel.y + 60, style = "radio", id = 2, onPress = onSwitchPressTheme, initialSwitchState = themeSaatIni[2], } radioTheme:insert( radioButtonTheme2 ) sceneGroup:insert( radioButtonTheme1 ) sceneGroup:insert( radioButtonTheme2 ) -- Create a group for the radio button set local radioGroup = display.newGroup() -- Create two associated radio buttons (inserted into the same display group) local radioButton1 = widget.newSwitch { left = 100, top = languageLabel.y + 20, style = "radio", id = "en", onPress = onSwitchPress, initialSwitchState = languageSaatIni[1], } radioGroup:insert( radioButton1 ) local radioButton2 = widget.newSwitch { left = 100, top = languageLabel.y + 60, style = "radio", id = "id", onPress = onSwitchPress, initialSwitchState = languageSaatIni[2], } radioGroup:insert( radioButton2 ) sceneGroup:insert( radioButton1 ) sceneGroup:insert( radioButton2 )

It’s clear that I have each group buttons separated from each other. Am I wrong?

Display objects can only be in one group at a time. Even though  you insert the radio button into the radio button group, when you later add the radio button to the sceneGroup, you’re in effect taking it out of the radioButton group. The solution is to only put the radio buttons into the radio button group, then insert the radio button group into sceneGroup instead of the individual buttons

Rob

Woah, I see. I’ll try.