I have tried without success to create an event listener that detects any new text entered into a textInput. I want the listener to call another function whenever the text is changed by just one character. Any advice is appreciated.

有帮助吗?

解决方案

Try this:

local function fctTextFieldListener(oEvent)
    if "began" == oEvent.phase then
        -- First edition
    elseif "editing" == oEvent.phase then
        -- During edition
    elseif "submitted" == oEvent.phase then
        -- End of edition
    end
end

local oTextField = native.newTextField( nX, nY, nWidth, nHeight)
oTextField:addEventListener( 'userInput', fctTextFieldListener )

You can access the oTextField text using oTextField.text :) In your case you would need to call your function either in the 'began' event if it's only on first edition, or 'editing' event on further editions.

Cheers

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top