Hello,
I’m building a business app with corona sdk , and basically i need consume a webservice, and put the information in a grid, and i need a checkbox in the first column of the grid to select 2 or more records ,
I’ve trying to do this with this tutorial http:\www.develephant.net/creating-a-data-grid-with-touch-in-corona-sdk
I have already made changes in this exemple , to put the column with the checkbox and put it in a vertical ScrollView , but i was not able to make the CheckBox work properly.
Here is my code :
function scene:createScene( event ) local data = { --row1 { image = display.newRect(0,0,20,40), label = "" }, { image = display.newImage("Images/gridHeader.png"), label = "Date" }, { image = display.newImage("Images/gridHeader.png"), label = "Number" }, --row2 { image = display.newImage("Images/checkBoxUnChecked.png"), label = "" }, { image = display.newImage("Images/gridLineWhite.png"), label = "12/08/15" }, { image = display.newImage("Images/gridLineWhite.png"), label = "036-000098"}, } --Create a grid cell "touch" listener local function onGridTouch( event ) local cellTouched = event.target --Get the cell Touched local cellData = data[cellTouched.dataIndex] --basically here i can check the cell touched and do a print or go to another page --but i can't change the image of the cell i've tried in this ways cellTouched.fill = "Images/gridLineWhite.png" cellTouched.image = "Images/gridLineWhite.png" cellTouched.displayNewImage("Images/gridLineWhite.png") -- this one change the image but not in the correctly place -- and here i can't get the position x,y of the cell , to create another image and put it above the old one if cellTouched.dataIndex == 8 then storyboard.gotoScene( "gridDetailsPrest","fade") end if cellTouched.dataIndex == 15 then storyboard.gotoScene( "gridDetailsAdto","fade") end end -------------------------Positioning grid in layout and adding the listener --Create grid display group gridDisplay = display.newGroup() for row=1, maxRow do for col=1, maxCol do g = display.newGroup() --Image (create rectangle if no image) local btn btn = data[dataIndex].image --Store an index to reference data btn.dataIndex = dataIndex g:insert( btn ) --Label local text = display.newText({ text = data[dataIndex].label, width = cellSize, height = 0, font = native.systemFont, fontSize = 10, align = "center" }) text:setTextColor( 0 ) text.x = btn.x text.y = btn.y+5 g:insert( text ) --CORRECTIONS BECAUSE THE CHECKBOX WIDTH IS SMALLER THAN OTHER CELLS if col ==2 then g.x = col \* 35 g.y = row \* cellSize else if col ~=1 then g.x = col \* cellSize-30 g.y = row \* cellSize else g.x = col \* cellSize g.y = row \* cellSize end end if row ~=1 then g.y = row \* (cellSize-10) end col = col + 1 if col \> maxCol then col = 1 row = row + 1 end --Add event listener btn:addEventListener( "tap", onGridTouch) gridDisplay:insert( g ) --Update data index dataIndex = dataIndex + 1 end end end
In simulater he looks like the image Attached
Of course in this code we don’t have the webservice part, it’s just the draft of the app , but my problem is to make the checkBox works
Thanks for the Help!