我正在使用KeyBoard对话框创建用户条目。我保留了两个按钮“OK”和“CANCEL”。但是在使用buttonSelected
时,它使用observeField调用该按钮。现在,任何人都可以告诉我如何使用buttonSelected
索引获取操作,同时单击一个按钮为OK并取消
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
]]>
答案 0 :(得分:4)
在此处创建一个函数和对话框。在对话框中,写观察字段的用法:第一个是“字段名称”,另一个是“函数名称”。 m.top.dialog.observeField("buttonSelected","onVerifyURL")
。
sub onVerifyURL()
if m.top.dialog.buttonSelected = 0
print "ok button pressed" 'O is called first
'function call for OK
else if m.top.dialog.buttonSelected = 1
print "cancel button pressed" '1 is called first
'm.top.dialog.visible = false
'm.top.dialog.close = true
else
print "nothing press" ' this is not required for code just write for an understanding
end if
end sub
答案 1 :(得分:0)
您是否检查了事件buttonSelected
内的内容; - )
答案 2 :(得分:0)
使用m.top.dialog.buttonSelected
将返回索引值。