Empty row - How fill with content and scenes

Hi everyone,

probably it’s a stupid question, but this it’s making me crazy… I’m building an app to donate to my city and i started doing that from the business application sample posted in the forum. I have the bottom bar and also graphical buttons in the menu.lua file. Now, the big problem: i can’t do a row with the list of offices. Reading on the forum and from corona resources I made a newTableView widget, but the row is completely empty, I’m not able to understand how insert text and images and, most of all, how to link to an “article” with office name, phone number, photo of the officer, map position and so on… Beyond that, with my actual code, the row stay visible also going to other scenes with the tabbar.

Please could you explain me how to do this? Thanks so much :slight_smile:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require( "widget" ) local myApp = require( "myapp" ) widget.setTheme(myApp.theme) local titleText local locationtxt local views = {} local function ignoreTouch( event ) return true end function scene:createScene(event) local group = self.view local background = display.newRect(0,0,display.contentWidth, display.contentHeight) background:setFillColor(242, 242, 242, 255) group:insert(background) background:addEventListener("touch", ignoreTouch) local statusBarBackground = display.newImageRect(myApp.topBarBg, display.contentWidth, display.topStatusBarContentHeight) statusBarBackground.x = display.contentCenterX statusBarBackground.y = display.topStatusBarContentHeight \* 0.5 group:insert(statusBarBackground) -- -- Create the other UI elements -- create toolbar to go at the top of the screen local titleBar = display.newImageRect(myApp.topBarBg, display.contentWidth, 50) titleBar.x = display.contentCenterX titleBar.y = 25 + display.topStatusBarContentHeight group:insert(titleBar) -- -- set up the text for the title bar, will be changed based on what page -- the viewer is on local function listener( event ) local shouldLoad = true local url = event.url if 1 == string.find( url, "corona:close" ) then -- Close the web popup shouldLoad = false end if event.errorCode then -- Error loading page print( "Error: " .. tostring( event.errorMessage ) ) shouldLoad = false end return shouldLoad end local options = { hasBackground=false, baseUrl=system.DocumentsDirectory, urlRequest=listener } titleText = display.newText( "Info", 0, 0, GillSans, 20 ) titleText:setTextColor( 255, 255, 255 ) titleText:setReferencePoint( display.CenterReferencePoint ) titleText.x = display.contentCenterX titleText.y = titleBar.height \* 0.5 + display.topStatusBarContentHeight group:insert(titleText) end local widget = require( "widget" ) -- Create a tableView local newTableView = widget.newTableView{ width = 320, height = 448, topPadding = 70, bottomPadding = 8, hideBackground = true, maskFile = "mask-320x448.png" } local rowText = {"Non", "ci","riesco"} local function onRowRender( event ) local phase = event.phase local row = event.row local rowTitle = display.newText( row, "some text", 0, 0, native.systemFont, 14 ) rowTitle.x = row.x - ( row.contentWidth \* 0.5 ) + ( rowTitle.contentWidth \* 0.5 ) rowTitle.y = row.contentHeight \* 0.33 rowTitle:setTextColor( 0, 0, 0 ) local someImage = display.newImageRect(row, "coffee1.png", 64, 25) someImage.x = row.contentWidth - 68 someImage.y = 15 end local function onRowTouch( event ) local row = event.row local background = event.background if event.phase == "press" then print( "Pressed row: " .. row.index ) background:setFillColor( 0, 110, 233, 255 ) elseif event.phase == "release" or event.phase == "tap" then director:changeScene("misc"..row.index) print( "Tapped and/or Released row: " .. row.index ) background:setFillColor( 0, 110, 233, 255 ) row.reRender = true end end -- insert rows into list (tableView widget) for i = 1, 3 do newTableView:insertRow{ height = 85, rowColor = { 255, 255, 255, 60 }, onRender = onRowRender, listener = onRowTouch } end function scene:destoryScene( event ) local group = self.view end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene 

Basically you need to get the row’s index and use it to look up data in your data table:

local function onRowRender( event )     local phase = event.phase      local row = event.row    local index = row.index     local rowTitle = display.newText( row, rowText[index], 0, 0, native.systemFont, 14 )     rowTitle.x = row.x - ( row.contentWidth \* 0.5 ) + ( rowTitle.contentWidth \* 0.5 )     rowTitle.y = row.contentHeight \* 0.33     rowTitle:setTextColor( 0, 0, 0 )     local someImage = display.newImageRect(row, "coffee1.png", 64, 25)     someImage.x = row.contentWidth - 68     someImage.y = 15 end

Now this only works if you’re not inserting divider/group rows where the table index is no longer in a 1 to 1 relationship with your data.  

Thanks Rob, this seems to work. In your opinion, what is the best way to build the pages with information? It’s better a table (I don’t know how to do this) or to build every single scene? Thank you very much

I’m not really sure I understand your goal. 

What is your data? 

Where are you getting it from? 

What format is it in already?

What is the intent of the different scenes or how do you plan to change the data?

Ok Rob thank you for your patience, I have never programmed before any software … my idea is to have scenes with a row of services. For example: List 1 SCENE 1: Service 1 Service 2 Service 3. With a tap of a service in the list, the app should show a “page” (Scene) with a short description, photos, phone number, and so forth. I can not understand how to build the table which should contain all these data (and if it is better to build it graphically with create.Scene). The list, the idea probably wrong that I have done, it should be a sort of “Menu”. Thanks for your help, it is truly appreciated.

If you’ve never programmed before, this might be a big project for you to start with…  It’s not a hard thing, but there are quite a few moving pieces that you need to learn before you can complete the app.  You’re already off to a good start.

What I would do is spend some time learning about lua tables and thinking about your data that you need.   Then you need to learn about how to have data available (google:  Corona Goodbye Globals) across scenes.  Then you will need a scene with your table as you’re building now and a “detail” scene that will show the details you want.  Then in your onRowTouch function you will load the detail storyboard scene.  You can pass the row index to the detail scene using it’s ability to pass parameters (you could even pass the table entry this way too) 

Yes I’m already studying and it’s very interesting and intuitive (most of the parts). Please could you suggest me some articles or posts to read for my case? I’ve read the lua table article and it was good to me, but still I can’t understand how to make all these things working together in the best way…

Basically you need to get the row’s index and use it to look up data in your data table:

local function onRowRender( event )     local phase = event.phase      local row = event.row    local index = row.index     local rowTitle = display.newText( row, rowText[index], 0, 0, native.systemFont, 14 )     rowTitle.x = row.x - ( row.contentWidth \* 0.5 ) + ( rowTitle.contentWidth \* 0.5 )     rowTitle.y = row.contentHeight \* 0.33     rowTitle:setTextColor( 0, 0, 0 )     local someImage = display.newImageRect(row, "coffee1.png", 64, 25)     someImage.x = row.contentWidth - 68     someImage.y = 15 end

Now this only works if you’re not inserting divider/group rows where the table index is no longer in a 1 to 1 relationship with your data.  

Thanks Rob, this seems to work. In your opinion, what is the best way to build the pages with information? It’s better a table (I don’t know how to do this) or to build every single scene? Thank you very much

I’m not really sure I understand your goal. 

What is your data? 

Where are you getting it from? 

What format is it in already?

What is the intent of the different scenes or how do you plan to change the data?

Ok Rob thank you for your patience, I have never programmed before any software … my idea is to have scenes with a row of services. For example: List 1 SCENE 1: Service 1 Service 2 Service 3. With a tap of a service in the list, the app should show a “page” (Scene) with a short description, photos, phone number, and so forth. I can not understand how to build the table which should contain all these data (and if it is better to build it graphically with create.Scene). The list, the idea probably wrong that I have done, it should be a sort of “Menu”. Thanks for your help, it is truly appreciated.

If you’ve never programmed before, this might be a big project for you to start with…  It’s not a hard thing, but there are quite a few moving pieces that you need to learn before you can complete the app.  You’re already off to a good start.

What I would do is spend some time learning about lua tables and thinking about your data that you need.   Then you need to learn about how to have data available (google:  Corona Goodbye Globals) across scenes.  Then you will need a scene with your table as you’re building now and a “detail” scene that will show the details you want.  Then in your onRowTouch function you will load the detail storyboard scene.  You can pass the row index to the detail scene using it’s ability to pass parameters (you could even pass the table entry this way too) 

Yes I’m already studying and it’s very interesting and intuitive (most of the parts). Please could you suggest me some articles or posts to read for my case? I’ve read the lua table article and it was good to me, but still I can’t understand how to make all these things working together in the best way…