Reputation: 47
I am trying to add the listener property to a slider component after creation:
local function sliderListener( _event )
print(_event.value)
end
slider = widget.newSlider
{
top = 30,
left = 10,
orientation = "vertical",
height = 200,
value = 10, -- Start slider at 10% (optional)
}
slider.listener = sliderListener
However... it doesn't work. Is this impossible or am I using the incorrect syntax?
Thanks in advance.
Upvotes: 0
Views: 407
Reputation: 224
You can assign the slider listener in tow ways. slider = widget.newSlider { top = 30, left = 10, orientation = "vertical", height = 200, value = 10, -- Start slider at 10% (optional) slider.listener = sliderListener }
or slider = widget.newSlider { top = 30, left = 10, orientation = "vertical", height = 200, value = 10, -- Start slider at 10% (optional) } slider.addEventListener("touch", sliderListener)
Upvotes: 0
Reputation: 29571
Not sure if the property must exist at creation time. Try:
slider = widget.newSlider
{
top = 30,
...
value = 10, -- Start slider at 10% (optional)
listener = sliderListener,
}
If you really need to set the handler after creation, instead use the above and set a delegate function to be used by sliderListener
. For example:
local actualListener
function actualListener1(event)
...
end
function actualListener2(event)
...
end
function sliderListener(event)
actualListener(event)
end
... create SliderWidget with listener = sliderListener...
actualListener = actualListener2
You could also make the sliderListener
a table that has a __call
(via setmetatable(s, {__call = Set.call})
Upvotes: 1