我正在使用Lua和Gideros并在按下后退按钮时显示警告框。根据Gideros文档,当按下第一个按钮时,它返回索引1,但它似乎不是这样工作。我测试过我的android手机上的应用程序。我意识到oncomplete功能根本没有被调用,因为我尝试使用print语句,即使它没有执行,所以任何想法为什么不被调用?
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)
答案 0 :(得分:1)
根据对话,问题是警报框关闭事件的事件监听器被附加到阶段而不是警告对话框。
stage:addEventListener(Event.COMPLETE, oncomplete)
而不是
alertDialog:addEventListener(Event.COMPLETE, oncomplete)