Director with list view

Hi everyone,

I am trying to put a list view in one of my screens while using the director class. Has anyone been able to successfully do it? What I am doing is pulling up a very simple list view after pressing a button. Does anyone have a very basic sample of how they accomplished this? Thanks in advance. [import]uid: 31262 topic_id: 6729 reply_id: 306729[/import]

Yes, I do this a lot in my app. In your “Screen2” (the one with the list view), your new() routine would be something like this:
[lua]function new()
local group = display.newGroup()
local back = display.newRect( 0, 0, display.contentWidth, display.contentHeight)
back:setFillColor( 0,0,0)
group:insert(back)

local listData = {“Line1”,“Line2”,“Line3”,“whatever”}
local list = tableView.newList{
data = listData,
callback = function(row, id)
local t = display.newText( row, 0, 0, nil, size)
t:setTextColor(255,255,255)
return t
end
}
group:insert(list)

local function touchHandler( event )
if event.phase == “ended” then
director:changeScene(“mainForm”,“moveFromLeft”)
return true
end
end

back:addEventListener(“touch”, touchHandler)
return group
end[/lua]
However, also see my post here: http://developer.anscamobile.com/forum/2011/02/16/memory-leak-list-views-tableviewlua regarding a memory leak in the List View that causes trouble with Director.

Use the new Director 1.2 and then make your “list” variable local to the Screen2 module (remove the “local” keyword in front of “list” in the new() routine) and then add a cleanup function:
[lua]function clean()
if list then list:cleanUp(); list = nil end
end[/lua]
This will properly clean up the list when you exit this screen. [import]uid: 12529 topic_id: 6729 reply_id: 23465[/import]

Thanks so much mpotter. Being so new at this I’m finding that there are a lot of samples on how to do the more complicated things and not so much help on how to do the more straight forward. Appreciate your help. [import]uid: 31262 topic_id: 6729 reply_id: 23481[/import]

@MPotter - can you put together a downloadable/emailable sample that incorporates the list view (acting like a menu) wrapped in director that then loads other screens?

Much like the director class sample but instead of the buttons on screen1.lua have the scrolling list view.

  • davey (davey at a3mg dot com) [import]uid: 7845 topic_id: 6729 reply_id: 32489[/import]