问题
I am new to Corona and I have a set of 10 question and the input is in the range from 0-8. I have code it such that my numeric textbox will loop for i times (i = number of question in array).
My question is how do I insert these value that is being keyed in into the database that i have created? Do i need to assign these individual question with a variable?
local madrs = display.newGroup()
local function textListener( event )
if ( event.phase == "began" ) then
elseif ( event.phase == "ended" or event.phase == "submitted" ) then
-- Output resulting text from "defaultField"
print( event.target.text )
elseif ( event.phase == "editing" ) then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
-- Create text field
madrs = native.newTextField( 640, 150 + (i * 450), 100, 100 )
madrs.inputType = "number"
madrs:addEventListener( "userInput", textListener )
madrs.font = native.newFont( native.systemFontBold, 50 )
scrollView:insert( madrs )
If you are unsure of what i am asking, feel free to comment down below i will clarify the question with you.
回答1:
You first need to ask yourself if you really need a SQL/SQLite database to store your data. I would say that 99% of the Corona apps would run as fine if you just store the data as a txt file (usually using JSON format).
If you still want to use SQLite, just take a look at the documentation for you. It provides example on how to execute queries (in your case, INSERT)
Link for Corona/Lua SQLite : https://docs.coronalabs.com/api/library/sqlite3/index.html
来源:https://stackoverflow.com/questions/48201469/corona-textbox-loop-into-database