Orlo
Orlo

Reputation: 828

widget.newSwitch() On-Off Switch doesn't work when "moved"

On-Off Switch - widget.newSwitch() doesn't work when I "move" the switch, it works only when I press.

I've tried setting "onEvent" but looks like it's completely ignored as nothing happens.

local widget = require( "widget" )

-- Handle press events for the checkbox
local function onSwitchPress( event )
    local switch = event.target
    print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) )
end

-- Create the widget
local onOffSwitch = widget.newSwitch
{
    left = 250,
    top = 200,
    style = "onOff",
    id = "onOffSwitch",
    onPress = onSwitchPress
}

Upvotes: 0

Views: 232

Answers (1)

sbajaj
sbajaj

Reputation: 59

The On-Off switch widget has two states: onPress and onRelease.
OnPress is called when we touch the switch.
OnRelease is called when we release the switch.
There is no event like onMove. This is why you cannot tap the move event.

See the link for more details.

Upvotes: 0

Related Questions