qq_36189789 2017-11-24 08:08 采纳率: 0%
浏览 3267

请问写了一个editbox,获取的是setTExt里的内容,怎么让他得到的是输入的的内容?

local editbox_account = ccui.EditBox:create(cc.size(dark_bg:getContentSize().width,dark_bg:getContentSize().height), ccui.Scale9Sprite:create(),nil,nil)
editbox_account:setFontColor(cc.c3b(0,0,0))
editbox_account:setText("1")
editbox_account:setReturnType(cc.KEYBOARD_RETURNTYPE_DONE )
editbox_account:setAnchorPoint(0.5,0.5)
editbox_account:setMaxLength(30)
editbox_account:setPosition(dark_bg:getContentSize().width/2, dark_bg:getContentSize().height/2)
editbox_account:setPlaceholderFontColor(cc.c3b(255,255,255))
editbox_account:setFontName("Helvetica")
editbox_account:setPlaceholderFontName("Helvetica")
editbox_account:setFontSize(24)
editbox_account:setPlaceholderFontSize(24)
editbox_account:setInputMode(cc.EDITBOX_INPUT_MODE_NUMERIC)
dark_bg:addChild(editbox_account)
editbox_account:setHACenter()
count_num = tonumber(editbox_account:getText())
count_label:setString(editbox_account:getText())
获取的是setTExt里的内容,怎么让他得到的是输入的的内容?
编辑框加上去了,点击的时候会弹出一个 input 对话框,
还有个问题怎么能让它不弹出输入框直接输入文字?

  • 写回答

1条回答 默认 最新

  • 凯神 2018-03-02 05:58
    关注

    获取输入框的内容可用在注册的回调函数中调用_editBox:getText(),就像下面这样:

    local _editBox = nil

    local function editBoxTextEventHandle( event )

    local filter = string.lower(_editBox:getText())
    if string.len(filter) > 0 then

    end

    end

    _editBox = ccui.EditBox:create(size, ccui.Scale9Sprite:create(),ccui.Scale9Sprite:create(),ccui.Scale9Sprite:create())
    _editBox:setAnchorPoint(0,0.5)
    _editBox:setPosition(-435,245)
    _editBox:setFontColor(cc.c4b(0,0,0,255))
    --注册脚本回调函数
    _editBox:registerScriptEditBoxHandler(editBoxTextEventHandle)
    node:addChild(_editBox,1)

    脚本回调函数:
    local function editboxEventHandler(eventType)
    if eventType == "began" then
    -- triggered when an edit box gains focus after keyboard is shown
    --当editbox获取焦点时调用
    elseif eventType == "ended" then
    -- triggered when an edit box loses focus after keyboard is hidden.
    --当editbox失去焦点时调用
    elseif eventType == "changed" then
    -- triggered when the edit box text was changed.
    --当editbox中的内容改变时调用
    elseif eventType == "return" then
    -- triggered when the return button was pressed or the outside area of keyboard was touched.
    --当按了return按钮或者键盘外的区域时调用
    end
    end

    评论

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型