Setting variables using radio buttons

I have an app with a main screen, and a couple pop-up screens that do a storyboard transition when I click a button.

I would like to be able to set values for text fields on the main screen, by clicking on radio buttons on the pop-up screens. I am trying to figure out how to get the id of the radio button, so I can set the values in the main screen.

I used:

    local function onRetKeyPress( event )

        local rb = event.target

        print( rb )

    end

to see if I could determine which radio button was selected, but nothing is ever printed in the terminal screen.

If someone could give me some pointers in this situation, I’d appreciate it.

I fiddled around some more. Now I get a table value in hexadecimal in the terminal window when I select a button (ie: table: 0x7feeec878a10).

How am I able to test against this when it changes any time I close the pop-up and reopen it?

This should give you more info:

for key,value in pairs(event.target) do print( key, value ) end

Also from the documentation:

– Listen for segmented control events
local function onSegmentPress( event )
  local target = event.target
  print( “Segment Label is:”, target.segmentLabel )
  print( “Segment Number is:”, target.segmentNumber )
end

Hi @sdzafovic,

Are you using the “radio” type of “widget.newSwitch()”? Or are you using “widget.newButton()”? If the first, you can see an example of how to set an ID on a radio button on this page:

http://docs.coronalabs.com/api/library/widget/newSwitch.html

Hope this helps,

Brent

Thanks. I switched to using regular widget buttons instead of radio buttons, and was finally able to get them to insert text where I wanted on my main screen, after hunting down somewhere else in the forum that I needed (event.target.id) to make the proper determination of the value.

But now I can’t seem to actually do anything with those values. But’s that’s an issue with my function I am assuming, so I’ll start a new topic.

I fiddled around some more. Now I get a table value in hexadecimal in the terminal window when I select a button (ie: table: 0x7feeec878a10).

How am I able to test against this when it changes any time I close the pop-up and reopen it?

This should give you more info:

for key,value in pairs(event.target) do print( key, value ) end

Also from the documentation:

– Listen for segmented control events
local function onSegmentPress( event )
  local target = event.target
  print( “Segment Label is:”, target.segmentLabel )
  print( “Segment Number is:”, target.segmentNumber )
end

Hi @sdzafovic,

Are you using the “radio” type of “widget.newSwitch()”? Or are you using “widget.newButton()”? If the first, you can see an example of how to set an ID on a radio button on this page:

http://docs.coronalabs.com/api/library/widget/newSwitch.html

Hope this helps,

Brent

Thanks. I switched to using regular widget buttons instead of radio buttons, and was finally able to get them to insert text where I wanted on my main screen, after hunting down somewhere else in the forum that I needed (event.target.id) to make the proper determination of the value.

But now I can’t seem to actually do anything with those values. But’s that’s an issue with my function I am assuming, so I’ll start a new topic.