1

我正在使用键盘对话框进行用户输入。我保留了两个按钮“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



]]>
4

3 回答 3

2

在这里,为对话框创建一个函数。在对话框中写入观察字段,如下所示示例:第一个参数是“字段名称”,另一个参数是“函数名称”

m.top.dialog.observeField("buttonSelected","onVerifyURL").

Function 下面是一个观察字段 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
于 2019-06-11T04:50:59.247 回答
0

你检查buttonSelected过事件里面有什么吗;-)

于 2016-08-23T04:08:34.707 回答
0

使用m.top.dialog.buttonSelected它将返回索引值。

于 2016-12-08T10:01:39.403 回答