Hi guys!
You see, I like this: “I do is write a text in a text field and then press the button to print the results in a multiline textbox”. What I think I am doing wrong I have marked in the code. Could help it work the way I want?
[lua]
require “sqlite3”
local path = system.pathForFile(“dattabase.db”, system.DocumentsDirectory)
db = sqlite3.open( path )
local function onSystemEvent( event )
if( event.type == “applicationExit” ) then
db:close()
end
end
local tablesetup = [[CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, message);]]
print(tablesetup)
db:exec( tablesetup )
–Here is where the error is safe, could explain how to do it?
for row in db:nrows(“SELECT * FROM test”) do
local text = row.message
local t = native.newTextBox( text, 15, 300, 320, 290 * row.id, null, 16 )
t:setTextColor(255,255,255)
end
local defaultField
local function buttonEvent (event)
if event.phase == “began” then
elseif event.phase == “moved” then
elseif event.phase == “ended” or event.phase == “cancelled” then
tablesetup =[[INSERT INTO test VALUES (NULL, ‘]]…message…[[’);]]
db:exec( tablesetup )
–(bis)
for row in db:nrows(“SELECT * FROM test”) do
local text = row.message
local t = native.newTextBox( text, 15, 300, 320, 290 * row.id, null, 16 )
t:setTextColor(255,255,255)
end
end
return true
end
– TextField Listener
local function fieldHandler( getObj )
return function( event )
print( "TextField Object is: " … tostring( getObj() ) )
if ( “began” == event.phase ) then
elseif ( “ended” == event.phase ) then
print( "Text entered = " … tostring( getObj().text ) )
elseif ( “submitted” == event.phase ) then
native.setKeyboardFocus( nil )
end
end
end
defaultField = native.newTextField( 0, 360, 320, 100,
fieldHandler( function() return defaultField end ) )
button = display.newImage(“buttondemo.png”)
button.x = 160
button.y = 470
button:addEventListener( “touch”, buttonEvent )
[/lua]
Thanks! [import]uid: 192093 topic_id: 36088 reply_id: 336088[/import]