I am making a user entry using KeyBoard dialog. I have kept two buttons "OK" and "CANCEL". But on using buttonSelected
it is calling both the button using observeField. Now, can anyone tell me how to use buttonSelected
index for getting action while clicking on one button as OK and Cancel
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
]]>
Here, Create one function for the dialog box. Inside a dialog box write observe field it's used Like below Example: First Parameter is a "Field name" and Another Parameter is a "Function name" .
m.top.dialog.observeField("buttonSelected","onVerifyURL")
.
Below Function is a point to observe field Second Parameter "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 second
'm.top.dialog.visible = false
'm.top.dialog.close = true
'function call for Cancel
else
print "nothing press" ' this is not required for code just write for an understanding
end if
end sub
您是否检查过事件中的buttonSelected
内部buttonSelected
;-)
使用m.top.dialog.buttonSelected
将返回索引值。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.