using newTableView

Hi everyone,

I’m new as a developer in Corona and I’m developing an app for purposes of a investigation in frameworks for making apps in android. I have the following issue: I’m creating an listview using the widget TableView but and the end all the rows are white or empty I don’t know why?

here is my code:

local composer = require ( “composer” )

local widget = require(“widget”)

–Create a storyboard scene for this module

local scene = composer.newScene()

–listview variables

–listview variables

–Create the scene

function scene:create( event )

    local sceneGroup = self.view

    --Set the background to white

    --display.setDefault( “background”, 1, 1, 1 )

    

    – Create a background to go behind our tableView

local background = display.newImage( “bg.jpg”, 0, 0, true )

background.anchorX = 0; background.anchorY = 0 – TopLeft anchor

    sceneGroup:insert( background )

    – Create a tableView

lista = widget.newTableView

{

top = 60,

width = 320, 

height = 448,

hideBackground = true,

onRowRender = onRowRender,

onRowTouch = onRowTouch,

listener = scrollListener

}

local myData = {}

myData[1] = { name=“Fred”,    phone=“555-555-1234” }

myData[2] = { name=“Barney”,  phone=“555-555-1235” }

myData[3] = { name=“Wilma”,   phone=“555-555-1236” }

myData[4] = { name=“Betty”,   phone=“555-555-1237” }

myData[5] = { name=“Pebbles”, phone=“555-555-1238” }

myData[6] = { name=“BamBam”,  phone=“555-555-1239” }

myData[7] = { name=“Dino”,    phone=“555-555-1240” }

for i = 1, #myData do

  lista:insertRow{

     rowHeight = 60,

     isCategory = false,

     rowColor = { 1, 1, 1 },

     lineColor = { 0.90, 0.90, 0.90 }

  }

end

local function onRowRender( event )

   --Set up the localized variables to be passed via the event table

  local row = event.row

  local id = row.index

  row.bg = display.newRect( 0, 0, display.contentWidth, 60 )

  row.bg.anchorX = 0

  row.bg.anchorY = 0

  row.bg:setFillColor( 1, 1, 1 )

  row:insert( row.bg )

  row.nameText = display.newText( myData[id].name, 12, 0, native.systemFontBold, 18 )

  row.nameText.anchorX = 0

  row.nameText.anchorY = 0.5

  row.nameText:setFillColor( 0 )

  row.nameText.y = 20

  row.nameText.x = 42

  row.phoneText = display.newText( myData[id].phone, 12, 0, native.systemFont, 18 )

  row.phoneText.anchorX = 0

  row.phoneText.anchorY = 0.5

  row.phoneText:setFillColor( 0.5 )

  row.phoneText.y = 40

  row.phoneText.x = 42

  row.rightArrow = display.newImageRect( “rowArrow.png”, 15 , 40, 40 )

  row.rightArrow.x = display.contentWidth - 20

  row.rightArrow.y = row.height / 2

  row:insert( row.nameText )

  row:insert( row.phoneText )

  row:insert( row.rightArrow )

  return true

end

–Insert widgets/images into a group

sceneGroup:insert( lista )

end    

–Create the scene

function scene:show( event )

   local sceneGroup = self.view

   local phase = event.phase

   

   if ( phase == “will” ) then

      – Called when the scene is still off screen (but is about to come on screen).

      – crea el textfield

   elseif ( phase == “did” ) then

   

   

        

   end --endif show

    

end --show

– “scene:hide()”

function scene:hide( event )

    local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “will” ) then

        – Called when the scene is on screen (but is about to go off screen).

        – Insert code here to “pause” the scene.

        – Example: stop timers, stop animation, stop audio, etc.

    elseif ( phase == “did” ) then

        – Called immediately after scene goes off screen.

        composer.removeHidden()

    end

end    

–Add the createScene listener

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

return scene

please anyone could please tell me what is happening?

i add some screenshot of the listview.

Thanks

I think you are suffering from what’s known as a “Scope” problem.  Corona SDK is sort of a one pass compiler.   That is, when it scans down your code and you do things like:

lista = widget.newTableView {     top = 60,     width = 320,      height = 448,     hideBackground = true,     onRowRender = onRowRender,     onRowTouch = onRowTouch,     listener = scrollListener }

I think you are suffering from what’s known as a “Scope” problem.  Corona SDK is sort of a one pass compiler.   That is, when it scans down your code and you do things like:

lista = widget.newTableView {     top = 60,     width = 320,      height = 448,     hideBackground = true,     onRowRender = onRowRender,     onRowTouch = onRowTouch,     listener = scrollListener }