简体   繁体   中英

Android Corona sdk textInput event listener for new text

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM