Type Function
Library widget.*
Return value none
Revision 2017.3112
Keywords widget, switch, radio, on-off, checkbox, SwitchWidget, setState
See also widget.newSwitch()


Used to programatically set the state of a SwitchWidget. This also changes the state of the switch visually.


object:setState( options )

This function takes a single argument, options, which is a table that accepts the following parameters:

isOn (required)

Boolean. Sets the switch to either on (true) or off (false).

isAnimated (optional)

Boolean. Applies only to switches with style of "onOff". If set to true, the switch will visually animate its state change.

onComplete (optional)

Listener. A callback function to be called when the switch has changed state.


-- Create a default on/off switch
local onOffSwitch = widget.newSwitch
    left = 100,
    top = 300,
    initialSwitchState = true

local function changeComplete()
    print( "Switch change complete!" )

-- Set the on/off switch to off
onOffSwitch:setState( { isOn=false, isAnimated=true, onComplete=changeComplete } )