How do I add individual text and image for tableView?

Hello

I have been recently trying to figure out how I can add individual text and image. I had this method done with Widget 1.0 but when Widget 2.0 came it end up braking the the entire method that I need help. I’m not good when it comes to using tableViews. How would I convert the code I have here to Widget 2.0.

local list = widget.newTableView{     width = 320,     height = 448,     bottomPadding = 8,     hideBackground = true,     maskFile = "mask-320x448.png" } list.y = titleBar.y + titleBar.contentHeight \* 0.5 widgetGroup:insert( list ) local rowText = {"floor", "sky","ground"}   local function onRowRender( event )         local row = event.row         local rowGroup = event.view         local label = "List item "         local color = 0         --Create the row's text           local thisRowText         if rowText[row.index] ~= nil then           thisRowText = rowText[row.index]         else           thisRowText = ""         end           row.textObj = display.newRetinaText( rowGroup, thisRowText, 0, 0,native.systemFontBold, 20 )         row.textObj:setTextColor( color )         row.textObj:setReferencePoint( display.CenterLeftReferencePoint )         row.textObj.x = 90         row.textObj.y = 40         rowGroup:insert( row.textObj )                  --Create the row's arrow         row.arrow = display.newImage( "rowArrow.png",false )         row.arrow.x = rowGroup.contentWidth - row.arrow.contentWidth \* 2         row.arrow.y = rowGroup.contentHeight \* 0.5         rowGroup:insert( row.arrow )                     row.arrow2 = display.newImageRect( "misc"..row.index..".png",60,60)         row.arrow2.x = 40         row.arrow2.y = rowGroup.contentHeight \* 0.5         rowGroup:insert( row.arrow2 )                 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     list:insertRow{         height = 85,         rowColor = { 255, 255, 255, 60 },         onRender = onRowRender,         listener = onRowTouch     }      end  

The part I’m always stump is at onRowRender function. That is where the error always happens.

Something like:

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, "someimage.png", 64, 25)     someImage.x = row.contentWidth - 68     someImage.y = 15   end

event.row is the display group for the row.  Just insert display objects into it and position as necessary.  If you need to look stuff up in a table of data that goes with each row, the value row.index lets you know which row you are working on.

Ah yes it did solve the problem, but I modified the text with the method you showed me in the past forum when you help me use tableView in version 1.0 like this

local rowText = {"sky","grass","ground"} local function onRowRender( event )   local phase = event.phase     local row = event.row                local thisRowText         if rowText[row.index] ~= nil then           thisRowText = rowText[row.index]         else           thisRowText = ""         end     local rowTitle = display.newText( row, thisRowText, 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, "blk"..row.index..".png", 60, 60)     someImage.x = row.contentWidth - 100     someImage.y = 40 end

Thank you very much for the help. You saved me from a disastrous problem that one my app was going to face in which it consist heavy use of tableView.

Something like:

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, "someimage.png", 64, 25)     someImage.x = row.contentWidth - 68     someImage.y = 15   end

event.row is the display group for the row.  Just insert display objects into it and position as necessary.  If you need to look stuff up in a table of data that goes with each row, the value row.index lets you know which row you are working on.

Ah yes it did solve the problem, but I modified the text with the method you showed me in the past forum when you help me use tableView in version 1.0 like this

local rowText = {"sky","grass","ground"} local function onRowRender( event )   local phase = event.phase     local row = event.row                local thisRowText         if rowText[row.index] ~= nil then           thisRowText = rowText[row.index]         else           thisRowText = ""         end     local rowTitle = display.newText( row, thisRowText, 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, "blk"..row.index..".png", 60, 60)     someImage.x = row.contentWidth - 100     someImage.y = 40 end

Thank you very much for the help. You saved me from a disastrous problem that one my app was going to face in which it consist heavy use of tableView.