I am using Lua with Gideros and having alert box to show up when back button is pressed.According to Gideros documentation, when first button is pressed, it returns index 1 but it does not really seem to work this way.I tested the app on my android phone.I realized the oncomplete function is not getting called at all, since I tried using a print statement and even it was not executed, so any idea why is is not getting called?

local function onKeyDown(event)
if event.keyCode == KeyCode.BACK then

        local alertDialog = AlertDialog.new("Confirmation", "Are you sure you want to exit?", "Cancel", "Yes")
        alertDialog:show()
        stage:addEventListener(Event.COMPLETE, oncomplete)
        end
end

function oncomplete(e)
if e.buttonIndex == 1 then 
stage:addEventListener(Event.APPLICATION_SUSPEND, suspend)
application: exit()
end

end

function suspend()
application: exit()
end

-- key events are dispatched to all Sprite instances on the scene tree (similar to mouse and touch events)
stage:addEventListener(Event.KEY_DOWN, onKeyDown)
有帮助吗?

解决方案

As per the conversation the issue was that the event listener for the alert box close event was being attached to the stage instead of the alert dialog.

stage:addEventListener(Event.COMPLETE, oncomplete)

instead of

alertDialog:addEventListener(Event.COMPLETE, oncomplete)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top