Hi guys,
I’m trying to make a multiple answer page with 5 options and the user can only select one otherwise the others will deselected which is why i’m using radio buttons not checkboxes. However, i’m now facing the issue that I want the user to be able to deselect their answer as the answer they want to select may be on a different scene. Any one know of a way to do this. Here is my code for my entire scene…
[lua]
–
– incidentReportingPg1.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
local myData = require( “myData” )
local function btnPrevious( event )
composer.gotoScene( “incidentReportingPg6”, { effect=“slideRight”, time=800} )
end
function scene:create( event )
local sceneGroup = self.view
–bg
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 0.9, 0.9, 0.9 ) – white
sceneGroup:insert( bg )
–titleHeader
local titleHeader = display.newImage( “titleHeader.png” )
titleHeader:translate( 160, -22 )
–title
local title = display.newText( “Incident Reporting”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = -25
–textPage
local textPage = display.newText(“Page 7”,
280,130, display.contentWidth -25 , display.contentHeight * 0.5, native.systemFont, 15 )
textPage:setFillColor( 0, 0, 0 )
–textWhatWas
local textWhatWas = display.newText(“What was the cause of the incident? (1 of 5)”,
172, 150, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 20 )
textWhatWas:setFillColor( 0, 0, 0 )
sceneGroup:insert( textWhatWas )
–textSlips
local textSlips = display.newText(“Slips, trip or fall on the same level”,
212, 219, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textSlips:setFillColor( 0, 0, 0 )
sceneGroup:insert( textSlips )
–textFallFrom
local textFallFrom = display.newText(“Fall from Height”,
212, 280, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textFallFrom:setFillColor( 0, 0, 0 )
sceneGroup:insert( textFallFrom )
–textBoxHeight
local textBoxHeight = native.newTextField( 200, 166, 75, 40 )
textBoxHeight.size = 20
textBoxHeight:addEventListener( “userInput”, textBoxHeight )
textBoxHeight.inputType = “number”
sceneGroup:insert( textBoxHeight )
–textInMeters
local textInMeters = display.newText(“In Meters”,
410, 280, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textInMeters:setFillColor( 0, 0, 0 )
sceneGroup:insert( textInMeters )
–textInjured
local textInjured = display.newText(“Injured whilst handling, lifting or carrying”,
212, 341, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textInjured:setFillColor( 0, 0, 0 )
sceneGroup:insert( textInjured )
–textHit
local textHit = display.newText(“Hit by an object”,
212, 402, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textHit:setFillColor( 0, 0, 0 )
sceneGroup:insert( textHit )
–textContact
local textContact = display.newText(“Contact with an object”,
212, 463, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textContact:setFillColor( 0, 0, 0 )
sceneGroup:insert( textContact )
–textMore
local textMore = display.newText("**More options are available on the next page**",
180, 500, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textMore:setFillColor( 0, 0, 0 )
sceneGroup:insert( textMore )
– Image sheet options and declaration
local options = {
width = 26,
height = 26,
numFrames = 2,
sheetContentWidth = 26,
sheetContentHeight = 52
}
local checkboxSheet = graphics.newImageSheet( “checkboxSheet.png”, options )
– 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 = 20,
top = 92,
style = “radio”,
id = “RadioButton1”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton1 )
sceneGroup:insert( radioButton1 )
local radioButton2 = widget.newSwitch
{
left = 20,
top = 153,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton2 )
sceneGroup:insert( radioButton2 )
local radioButton3 = widget.newSwitch
{
left = 20,
top = 214,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton3 )
sceneGroup:insert( radioButton3 )
local radioButton4 = widget.newSwitch
{
left = 20,
top = 275,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton4 )
sceneGroup:insert( radioButton4 )
local radioButton5 = widget.newSwitch
{
left = 20,
top = 336,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton5 )
sceneGroup:insert( radioButton5 )
local function OnbtnNext( event )
if event.phase == “ended” then
local radioOn = false
local textFilled = true
myData.fallHeight = textBoxHeight.text
if radioButton1.isOn == true then
myData.IRb4 = textSlips.text
end
if radioButton2.isOn == true then
myData.IRb4 = textFallFrom.text
radioOn = true
end
if radioButton3.isOn == true then
myData.IRb4 = textInjured.text
end
if radioButton4.isOn == true then
myData.IRb4 = textHit.text
end
if radioButton5.isOn == true then
myData.IRb4 = textContact.text
end
if textBoxHeight.text == “” or textBoxHeight.text == nil then
textFilled = false
end
if radioOn == true and textFilled then
composer.gotoScene( “incidentReportingPg8”, { effect=“slideLeft”, time=800,} )
end
if radioOn == true and textFilled == false then
local msg
if textFilled == false then
msg = “No input in textbox”
end
local alert = native.showAlert( “Warning”, "ERROR: "…msg, { “OK” }, onComplete)
end
if radioOn == false and textFilled == false then
composer.gotoScene( “incidentReportingPg8”, { effect=“slideLeft”, time=800,} )
end
end
return true
end
–btnPrevious
local btnPrevious = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnPrevious.png”,
onEvent = btnPrevious
}
btnPrevious.x = 84
btnPrevious.y = 445
–btnNext
local btnNext = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnNext.png”,
onEvent = OnbtnNext
}
btnNext.x = 235
btnNext.y = 445
–sceneGroup
sceneGroup:insert( titleHeader )
sceneGroup:insert( title )
sceneGroup:insert( textPage )
sceneGroup:insert( btnNext )
sceneGroup:insert( btnPrevious )
end
function scene:show( event )
local sceneGroup = self.view
end
function scene:hide( event )
local sceneGroup = self.view
end
function scene:destroy( event )
local sceneGroup = self.view
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
Thanks again,
Matt.