Hello!
From the documentation for the native new text fields, the following multiple inputs are using the same listener:
[lua]
local defaultField, numberField – forward reference (needed for Lua closure)
– TextField Listener
local function fieldHandler( getObj )
– Use Lua closure in order to access the TextField object
return function( event )
print( "TextField Object is: " … tostring( getObj() ) )
if ( “began” == event.phase ) then
– This is the “keyboard has appeared” event
elseif ( “ended” == event.phase ) then
– This event is called when the user stops editing a field:
– for example, when they touch a different field or keyboard focus goes away
print( "Text entered = " … tostring( getObj().text ) ) – display the text entered
elseif ( “submitted” == event.phase ) then
– This event occurs when the user presses the “return” key
– (if available) on the onscreen keyboard
– Hide keyboard
native.setKeyboardFocus( nil )
end
end – “return function()”
end
– Create our Text Field
defaultField = native.newTextField( 10, 30, 180, 30 )
local function defaultHandler( event )
fieldHandler( function() return defaultField end ) – passes the text field object
end
defaultField:addEventListener( “userInput”, defaultHandler )
numberField = native.newTextField( 10, 70, 180, 30 )
local function numberHandler( event )
fieldHandler( function() return numberField end )
end
numberField:addEventListener( “userInput”, numberHandler )
[/lua]
How can I get the entered text from each one of the fields at a later time after a user has entered data in all the fields, and not as the events are fired off? I have a user entering his/her first and last name and then a submit button. I want to be able to get the info once the user has hit the submit button.
Appreciate any help!
-Mario