I’ve implemented a native.textField into my app, and the user can input data and press the “Done” button on the keyboard, but I can’t figure out how to then display the text that the user typed in onto the screen.
So, in example, I’d like for the user to type in, say, “Text” and then upon pressing “Done” on the keyboard the screen would display “Text”.
I used the basic example in the Corona API to create the textfield, which looks like the following. Any help would be great!
local defaultField
local function textListener( event )
if event.phase == “began” then
– user begins editing textField
print( event.text )
elseif event.phase == “ended” then
– textField/Box loses focus
elseif event.phase == “ended” or event.phase == “submitted” then
– do something with defaulField’s text
elseif event.phase == “editing” then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
– Create our Text Field
defaultField = native.newTextField( 10, 30, 180, 30 )
defaultField.userInput = textListener
defaultField:addEventListener( “userInput”, defaultField )