我正在使用键盘对话框进行用户输入。我保留了两个按钮“OK”和“CANCEL”。但是在使用buttonSelected
它时使用observeField调用两个按钮。现在,谁能告诉我如何使用buttonSelected
索引来获取操作,同时单击一个按钮作为确定和取消
sub init()
m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
example = m.top.findNode("instructLabel")
examplerect = example.boundingRect()
centerx = (1280 - examplerect.width) / 2
centery = (720 - examplerect.height) / 2
example.translation = [ centerx, centery ]
m.top.setFocus(true)
end sub
sub showdialog()
keyboarddialog = createObject("roSGNode", "KeyboardDialog")
keyboarddialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
keyboarddialog.title = "Example Keyboard Dialog"
keyboarddialog.buttons=["OK","CANCEL"]
keyboarddialog.optionsDialog=true
m.top.dialog = keyboarddialog
print "hello"
KeyboardDialog.observeField("buttonSelected","onKeyPress")
' KeyboardDialog.observeField("buttonSelected","onKeyPressCancel")
print "world"
end sub
function onKeyPress()
print "m.value:::>>"m.top.dialog.text
end Function
function onKeyPressCancel()
print "Screen should close"
end Function
function onKeyEvent(key as String, press as Boolean) as Boolean
if press then
if key = "OK"
showdialog()
return true
end if
end if
return false
end function
]]>