http://developer.coronalabs.com/code/table-view-library
I’m having a hard time with Table Views. I run the simulator with the ListView2 demo, and I click on one of the List Items I get this “You tapped item 1”, or “You tapped item 5”, etc…
How do I replace the number with something else? Like the title, or category text, or a specific number (like from sqlite)?
My Table View is populated from sqlite3, and I’m not quite understanding how to force the text to say something like: "You tapped Database ID: "… pass my db ID here
Here’s my sample code, using a news table:
-- setup some data
local data = {}
for row in db:nrows("SELECT \* FROM news ORDER BY date DESC") do
data[i] = {}
data[i].newsID = row.newsID
data[i].title = "News Title: "..row.title
local c = math.modf(i/5)
data[i].category = "Category ".. c + 1
end
-- Create a list with header titles
myList = tableView.newList{
data=data,
default="listItemBg.png",
over="listItemBg\_over.png",
onRelease=listButtonRelease,
top=topBoundary,
bottom=bottomBoundary,
cat="category",
categoryBackground="catBg.png",
backgroundColor={ 255, 255, 255 },
callback=function(item)
local t = display.newText(item.title, 0, 0, native.systemFontBold, textSize)
t:setTextColor(0, 0, 0)
t.x = math.floor(t.width/2) + 12
t.y = 46
return t
end
}
And here’s the function that executes the text “You tapped item…”
--setup functions to execute on touch of the list view items
function listButtonRelease( event )
self = event.target
local id = self.id
print(self.id)
detailScreenText.text = "You tapped item ".. self.id
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
self.id is what I obviously want to replace with the database newsID I extracted from the query. That’s where I’m getting hung up on.
Does this make sense?
[import]uid: 154122 topic_id: 28822 reply_id: 328822[/import]