Change scene from list item

Hello, I need some help regarding list. When I click on the cell how do I make it to change scene using director?

Thank you. [import]uid: 121356 topic_id: 21278 reply_id: 321278[/import]

Hello,
If your using director
this is very helpful…

http://www.youtube.com/watch?v=KudLE8h4kWw

Best Regards,

Larry
[import]uid: 107633 topic_id: 21278 reply_id: 84266[/import]

@aakashroychaudhury here would be an example I ran to the same you had. this is the code for how you want to change scene from cells using director.
place this in the main.lua

[code]display.setStatusBar (display.HiddenStatusBar)
–> Hides the status bar

local director = require (“director”)
–> Imports director

local mainGroup = display.newGroup()
–> Creates a main group

local function main()
–> Adds main function

mainGroup:insert(director.directorView)
–> Adds the group from director

director:changeScene(“menu”)
–> Change the scene, no effects

return true
end

main() [/code]

Then place this on the next scene were the cells are I called mines menu.lua you can change yours.

[code]module(…, package.seeall)

function new()
local localGroup = display.newGroup()
local tableView = require(“tableView”)

–import the button events library
local ui = require(“ui”)

display.setStatusBar( display.HiddenStatusBar )
–initial values
local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight

local myList, backBtn, detailScreenText

local background = display.newRect(0, 0, display.contentWidth, display.contentHeight)
background:setFillColor(77, 77, 77)
localGroup:insert(background)

–setup a destination for the list items
local detailScreen = display.newGroup()

local detailBg = display.newRect(0,0,display.contentWidth,display.contentHeight-display.screenOriginY)
detailBg:setFillColor(255,255,255)
detailScreen:insert(detailBg)
localGroup:insert(detailBg)

detailScreenText = display.newText(“You tapped item”, 0, 0, native.systemFontBold, 24)
detailScreenText:setTextColor(0, 0, 0)
detailScreen:insert(detailScreenText)
detailScreenText.x = math.floor(display.contentWidth/2)
detailScreenText.y = math.floor(display.contentHeight/2)
detailScreen.x = display.contentWidth

local mySceneTable = {“view 1”, “view 2”}

–setup functions to execute on touch of the list view items
function listButtonRelease( event )
self = event.target
local id = self.id
print(self.id)
director:changeScene(mySceneTable[self.id], “crossfade”)
end

function backBtnRelease( event )
print(“back button released”)
transition.to(myList, {time=400, x=0, transition=easing.outExpo })
transition.to(detailScreen, {time=400, x=display.contentWidth, transition=easing.outExpo })
transition.to(backBtn, {time=400, x=math.floor(backBtn.width/2)+backBtn.width, transition=easing.outExpo })
transition.to(backBtn, {time=400, alpha=0 })

delta, velocity = 0, 0
end

local data = {}
local displaytext = {“mil”, “List item 2”}
local imageTable = {“backButton.png”, “backButton.png”}
local imageTableY = {50,50}
local imageTableX = {100,100}
– you have to have an image for each piece of text
for i=1, 2 do
data[1] = {}
data[1].text = displaytext[1]
data[1].image = imageTable[1]
data[1].imageX = imageTableY[1]
data[1].imageY = imageTableX[1]

data[2] = {}
data[2].text = displaytext[2]
data[2].image = imageTable[2]
data[2].imageX = imageTableY[2]
data[2].imageY = imageTableX[2]
end

local topBoundary = display.screenOriginY + 40
local bottomBoundary = display.screenOriginY + 0

– create the list of items
myList = tableView.newList{
data=data,
default=“listItemBg.png”,
over=“listItemBg_over.png”,
onRelease=listButtonRelease,
top=topBoundary,
bottom=bottomBoundary,
backgroundColor={ 255, 255, 255 },
callback=function(row)
local g = display.newGroup()

local t = display.newText(row.text, 0, 0, native.systemFontBold, 16 )
t:setTextColor(0, 0, 0)
t.x = math.floor(t.width/2) + 12
t.y = 30
g:insert(t)

local img = display.newImageRect(row.image,row.imageY, row.imageX)
img.x = 100
img.y = 50
g:insert(img)
return g
end
}

–Setup the nav bar
local navBar = display.newImage(“navBar.png”, 0, 0, true)
navBar.x = display.contentWidth*.5
navBar.y = math.floor(display.screenOriginY + navBar.height*0.5)
localGroup:insert(navBar)

local navHeader = display.newText(“My List”, 0, 0, native.systemFontBold, 16)
navHeader:setTextColor(255, 255, 255)
navHeader.x = display.contentWidth*.5
navHeader.y = navBar.y
localGroup:insert(navHeader)

–Setup the back button
backBtn = ui.newButton{
default = “backButton.png”,
over = “backButton_over.png”,
onRelease = backBtnRelease
}
backBtn.x = math.floor(backBtn.width/2) + backBtn.width + screenOffsetW
backBtn.y = navBar.y
backBtn.alpha = 0
localGroup:insert(backBtn)

return localGroup
end [/code]

This code above shows when changing when touching the cell

(This code below is the next scene when you click on the cell)

[code]module(…, package.seeall)

function new()
local localGroup = display.newGroup()

–import the button events library
display.setStatusBar( display.HiddenStatusBar )

local car = display.newText(“car”, 160, 240, “Arial” ,30)
return localGroup
end [/code]

This scene is call view 1.lua [import]uid: 17058 topic_id: 21278 reply_id: 84278[/import]

Thank you very much Larry but I think I am making some mistakes, it did not work for me in the list. [import]uid: 121356 topic_id: 21278 reply_id: 84357[/import]

Hello,

Thanks a lot for the code. This is exactly what I was looking for but still I have got a major issue with this. Now I am able to change screen but the problem which I am having is that when the screen is changing from the list items to view 1 or view 2, the items are still appearing into the next screen and I am not able to get rid of them.

Another thing is that I cannot put more than 2 items in the list as it is not working.

Thank you very much,

Regards,

Aakash. [import]uid: 121356 topic_id: 21278 reply_id: 84358[/import]

Like what items are appearing in the next scene.

Also to have more cells just edit this

[code]for i=1, 2 do
data[1] = {}
data[1].text = displaytext[1]
data[1].image = imageTable[1]
data[1].imageX = imageTableY[1]
data[1].imageY = imageTableX[1]

data[2] = {}
data[2].text = displaytext[2]
data[2].image = imageTable[2]
data[2].imageX = imageTableY[2]
data[2].imageY = imageTableX[2]
end [/code]

to have cell 3 or more just do this

[code]for i=1, 3 do
data[1] = {}
data[1].text = displaytext[1]
data[1].image = imageTable[1]
data[1].imageX = imageTableY[1]
data[1].imageY = imageTableX[1]

data[2] = {}
data[2].text = displaytext[2]
data[2].image = imageTable[2]
data[2].imageX = imageTableY[2]
data[2].imageY = imageTableX[2]
data[3] = {}
data[3].text = displaytext[3]
data[3].image = imageTable[3]
data[3].imageX = imageTableY[3]
data[3].imageY = imageTableX[3]
end [/code]

If your still struggling feel free to ask more questions

:slight_smile: [import]uid: 17058 topic_id: 21278 reply_id: 84409[/import]

Thanks for replying. Really sorry to bother you but the list page and the items are not disappearing when im clicking onto a row. For example, mil and list item 2 appearing in view 1 and view 2 page.

I have tried this to add more rows but no success, instead the program is not working.

data[3] = {}
data[3].text = displaytext[3]
data[3].image = imageTable[3]
data[3].imageX = imageTableY[3]
data[3].imageY = imageTableX[3]
Thanks again,

Aakash. [import]uid: 121356 topic_id: 21278 reply_id: 84410[/import]

He found it looks like this to display more cells

[code] local data = {}
local displaytext = {“mil”, “List item 2”, “car”}
local imageTable = {“backButton.png”, “backButton.png”,“backButton.png” }
local imageTableY = {50,50}
local imageTableX = {100,100}
– you have to have an image for each piece of text
for i=1, 1 do
data[1] = {}
data[1].text = displaytext[1]
data[1].image = imageTable[1]
data[1].imageX = imageTableY[1]
data[1].imageY = imageTableX[1]

data[2] = {}
data[2].text = displaytext[2]
data[2].image = imageTable[2]
data[2].imageX = imageTableY[2]
data[2].imageY = imageTableX[2]

data[3] = {}
data[3].text = displaytext[3]
data[3].image = imageTable[3]
data[3].imageX = imageTableY[1]
data[3].imageY = imageTableX[1]
end [/code]

This works I tested it [import]uid: 17058 topic_id: 21278 reply_id: 84412[/import]

I have to go now. I promise I will be back to help you. Also on question what did you put on view 1.lua? [import]uid: 17058 topic_id: 21278 reply_id: 84413[/import]

Thanks a ton. I can now add more rows to the list.

And for the other issue, I solved it. I did not put the following lines of code and that is why I was having the problem but all set now. Thank you very much for your help. May have to come back to you, if I face some more issues. Thanks.

Regards,

Aakash.

if
system.getInfo(“model”) == “iPad” then
selected.width, selected.height = self.width, self.height
selected.y = self.y + self.height*0.5
selected.isVisible = true
else
transition.to(myList, {time=400, x=display.contentWidth*-1, transition=easing.outExpo })
transition.to(detailScreen, {time=400, x=0, transition=easing.outExpo })
transition.to(backBtn, {time=400, x=math.floor(backBtn.width/2) + screenOffsetW*.5 + 6, transition=easing.outExpo })
transition.to(backBtn, {time=400, alpha=1 })

delta, velocity = 0, 0
end [import]uid: 121356 topic_id: 21278 reply_id: 84419[/import]

@aakashroychaudhury is the code below you posted you need help on that? [import]uid: 17058 topic_id: 21278 reply_id: 84507[/import]

Hello,

I was having the problem because I missed out those code but everything running smoothly now.

Thank you very much for your help.

Regards,

Aakash. [import]uid: 121356 topic_id: 21278 reply_id: 84510[/import]