Search code examples
androidsdklistenercoronasdktextinput

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.


Solution

  • 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