Hello im new here and im developing a business app with corona sdks, i followed this tutorial
http://www.develephant.net/creating-a-data-grid-with-touch-in-corona-sdk/
and adpted it to a grid with a check box in the first column , and now i want to check/uncheck the checkbox , this could be simple solved changing the image of the checkbox , but the problem is im trying to change the image , but isnt working , the image always start in the position 0,0 like a new one , and not in the same place that the other
function scene:createScene( event ) storyboard.purgeOnSceneChange = true local group = self.view local backGround = display.newImageRect('Images/img.png',screenW,screenH) local cellSize = 50 local row = 0 local col = 0 local maxRow = 11 local maxCol = 7 --Declaration of Grid objects local dataIndex = 1 local data = { --row1 { image = display.newImage("Images/checkBoxHeader.png"), label = "" }, { image = display.newImage("Images/gridHeader.png"), label = "Date" }, { image = display.newImage("Images/gridHeader.png"), label = "Number" }, { image = display.newImage("Images/gridHeader.png"), label = "type" }, { image = display.newImage("Images/gridHeader.png"), label = "Person" }, { image = display.newImage("Images/gridHeader.png"), label = "Currency" }, { image = display.newImage("Images/gridHeader.png"), label = "Amount" }, } --Create a grid cell "touch" listener to get the cell touched local function onGridTouch( event ) if event.phase == "ended" or event.phase == "cancelled" then local cellTouched = event.target --GET THE CELL TOUCHED local cellData = data[cellTouched.dataIndex] -- HERE I CAN RETRIEVE THE LABEL OF THE CELL BUT THE FOLLOWING LINE DON`T CHANGE -- THE IMAGE , THIS LINE CREATE ANOTHER IMAGE IN THE POSITION 0,0 AND I WAN`T TO -- CHANGE THE CURRENT IMAGE FOR ANOTHER TO SIMULATE A CHECK BOX cellData.image = display.newImage("Images/checkBoxChecked.png") end end --Create grid display group --CREATE THE GRID ON THE SCREEN OF APP local gridDisplay = display.newGroup() for row=1, maxRow do for col=1, maxCol do local g = display.newGroup() btn = data[dataIndex].image --Store an index to reference data btn.dataIndex = dataIndex --Add event listener FOR CELL TOUCH btn:addEventListener( "touch", onGridTouch ) g:insert( btn ) --Label local text = display.newText({ text = data[dataIndex].label, width = cellSize, height = 0, font = native.systemFont, fontSize = 10, align = "center" }) --ADJUSTE COLOR AND POSITION OF LABEL text:setTextColor( 0 ) text.x = btn.x text.y = btn.y+5 g:insert( text ) col = col + 1 if col \> maxCol then col = 1 row = row + 1 gridDisplay:insert( g ) --Update data index dataIndex = dataIndex + 1 end end end
In function onGridTouch i tried to change image, or get the x,y of the element to re-position the image but all failed , if anyone could help it will be nice
EDITED: To ident the code , because this was unedited after the copy and paste in forum and put another comments to try to help ,
Thanks for help