I’m coming back to Corona after a long break, and having to re-learn it.
I’ve watched this video but the code is not complete (function is missing “end” for example) and there doesn’t seem to be source code for it (see code below):
Corona University - Displaying Database Data Using TableView Widgets
It also doesn’t say how the data (apparently names in this example) got into the database in the first place.
What I’m trying to do is have a list the user clicks on, and a check mark shows for that row (which can just be a text check, doesn’t have to be a graphic).That row information is saved and can be show for the same table on another screen (see mockups).
I suppose all the data for the table should be kept in the database:
Number, Word, Meaning, Check
even though whether a row is checked or not is the only thing that changes?
I’ve also found code for creating a TableView where one can click on a row and a text check appears, and so want to combine these techniques. I also need to create columns and obviously save the onRowTouch event to the database.
Here’s part of the checkmark code:
-- Row (Touch) local function onRowTouch(touchEvent) local str = touchEvent.target.titleTxt.text .. "✔" touchEvent.target.titleTxt.text = str touchEvent.target.titleTxt:setFillColor(1, 0, 0, 1) end
Here’s the code from the video.
----------------------------------------------------------------------------------------- -- Table Database 1/4/15 -- -- main.lua -- ----------------------------------------------------------------------------------------- local widget = require( "widget" ) require( "sqlite3" ) local path = system.pathForFile("data.db", system.DocumentsDirectory) local db = sqlite3.open( path ) -- --------------------------------------------------------- -- Create Tableview widget -- --------------------------------------------------------- local table\_options = { top = 0, onRowRender = onRowRender, } local tableView = widget.newTableView( table\_options ) -- instead of the usual just listing in an array of options right here -- --------------------------------------------------------- -- Retrieve Database Data -- --------------------------------------------------------- for row in db:nrows("SELECT \* FROM test") do -- parameter lua table tableView:insertRow( { rowHeight = 50, params = rowParams, } ) -- --------------------------------------------------------- -- Handle Tableview Row Rendering -- --------------------------------------------------------- local function onRowRender( event ) -- Get reference to the row group local row = event.row -- common row elements local font = native.systemFont local fontSize = 24 local rowHeight = row.rowHeight / 2 -- display.newText options local options\_id = { parent = row, text = row.params.ID, x = 50, y = rowHeight, font = font, fontSize = fontSize, } -- add row object row.id = display.newText( options\_id) row.id.anchorX = 0 row.id:setFillColor( 1, 0, 0 ) -- display.newText options local options\_name = { parent = row, text = row.params.Name, x = 100, y = rowHeight, font = font, fontSize = fontSize, } -- add row object row.name = display.newText(options\_name)