I am looping through a table in SQLite and adding them in a scrollView like below. If I click on the previous screen where a button is placed it selects one of these buttons.
Here is the event code:
local function btnArtButtonEvent( event ) if ("ended" == event.phase ) then composer.setVariable( "artno", event.target.id ) composer.setVariable( "artfilename", event.target.fn ) local artno2 = event.target.id local filename2 = event.target.fn local width2 = event.target.width local height2 = event.target.height local posx2 = 0 local posy2 = 0 local orderno2 = composer.getVariable( "orderno" ) if orderno2 == nil or orderno2 == "" then orderno2 = "1234567" end tablefill3 = "INSERT INTO art (orderno, artno, posx, posy, width, height, filename ) VALUES ('" .. orderno2 .. "', '" .. artno2 .. "', " .. posx2 .. ", " .. posy2 .. ", " .. width2 .. ", " .. height2 .. ", '" .. filename2 .. "')" db:exec( tablefill3 ) RemoveAll() Runtime:removeEventListener( "key", onKeyEvent ) composer.gotoScene( "sceneDesign" ) end end
Button code:
imgArt[CT1] = widget.newButton { width = width2, height = height2, defaultFile = "images/art/" .. filename2, overFile = "images/art/" .. filename2, label = "", onEvent = btnArtButtonEvent } local s = 200/width2 imgArt[CT1]:scale(s, s) if height2 \> height3 then height3 = height2 end imgArt[CT1].anchorX = 0 imgArt[CT1].anchorY = 0 imgArt[CT1].y = Top8 if col3 == 1 then imgArt[CT1].x = col1 col3 = 2 else imgArt[CT1].x = col2 col3 = 1 Top8 = Top8 + height3 + 20 height3 = 0 end imgArt[CT1].id = artno2 imgArt[CT1].fn = filename2 imgArt[CT1].width = height2 imgArt[CT1].height = width2 scrollView:insert( imgArt[CT1] ) CT1 = CT1 + 1