Button widget for long press

Will corona support long press for button widget in the future? I read in one of the forum that you can use switch to listen for a long press event. How do you implement it? Can you show me a sample code? I’m kinda new to widget 2.0 right now. And I’m planning to make a new project using the new widget that will  includes long press event.

Thanks.

Yes…I have the same problem…bro…

Can anyone help us? :smiley:

You could make your own timer.

[lua]

local widget = require( “widget” )

    

    local pressTimer

    local function handleButtonEvent( event )

        local phase = event.phase

        if “began” == phase then

             pressTimer = os.time()

        elseif “ended” == phase then

             local timeHeld = os.time() - pressTimer

             if timeHeld >= 2 then

                  print(“Held for 2 sec or longer, do something”)

             else

                  print(“Held short, do something”)

             end

        end

    end

    

    – Create the button

    local myButton = widget.newButton

    {

        left = 100,

        top = 200,

        width = 150,

        height = 50,

        label = “Button”,

        onEvent = handleButtonEvent,

    }

[/lua]

Yes…I have the same problem…bro…

Can anyone help us? :smiley:

You could make your own timer.

[lua]

local widget = require( “widget” )

    

    local pressTimer

    local function handleButtonEvent( event )

        local phase = event.phase

        if “began” == phase then

             pressTimer = os.time()

        elseif “ended” == phase then

             local timeHeld = os.time() - pressTimer

             if timeHeld >= 2 then

                  print(“Held for 2 sec or longer, do something”)

             else

                  print(“Held short, do something”)

             end

        end

    end

    

    – Create the button

    local myButton = widget.newButton

    {

        left = 100,

        top = 200,

        width = 150,

        height = 50,

        label = “Button”,

        onEvent = handleButtonEvent,

    }

[/lua]

Like this and found well useful. One refinement was I used system.getTimer() as its gives millisecond resolution whereas os.timer() just gives integer seconds.

Like this and found well useful. One refinement was I used system.getTimer() as its gives millisecond resolution whereas os.timer() just gives integer seconds.