widget demo

Hi,

I just downloaded the new build #703 and while it fixed a problem with the pickerwheel it has created another problem for me. You see I had modified the widget demo in particular the tableview. The new tableview is different than the previous. I can’t seem to change the row title for individual rows to whatever I want.

I don’t know what is is more time economical, understand this new one or insert the previous code for that tableview.

I just want to be able to change the individual row titles and perform different methods on each row. [import]uid: 95689 topic_id: 18896 reply_id: 318896[/import]

It depends on what you mean by “title”. Are you talking about the actual text that appears on each entry? That’s really easy to change.

If you’re looking for some kind of row identifier, I believe it supports id (row.id) now…? [import]uid: 41884 topic_id: 18896 reply_id: 72786[/import]

Richard,

Yes, the title on each entry. You can change it but the same thing will appear on all rows. I do not want that. I need something different on each row.

Thanks [import]uid: 95689 topic_id: 18896 reply_id: 72828[/import]

For this you need to run a “for” loop.

If you take a look at the API page sample code, it runs a for loop that calls onRowRender for each entry. Therefore, in onRowRender, you can change it to, say, point at a table.

[code]
local text = display.newRetinaText( myTable[i], 12, 0, “Helvetica-Bold”, 18 )
– This would ensure that each row has the corresponding line from a table.

– or…

if event.index == 10 then
local text = display.newRetinaText( “This is #10!”, 12, 0, “Helvetica-Bold”, 18 )[/code]

It’s really quite flexible and there are a bunch of ways to approach it. Is this what you’re talking about? [import]uid: 41884 topic_id: 18896 reply_id: 72831[/import]

Thanks Richard, I will look it up ! [import]uid: 95689 topic_id: 18896 reply_id: 72832[/import]

Richard, thanks again,

I got it to display my data on each row as I needed, but now there’s a small problem:

I have two arrays, one for the data catagory and another for the data itself. I can’t seem to display both arrays for the same row. For now I display the data when that row is pressed but it goes away on release. Is there a way around this? Here is the code (“cat” is the catagory array and “plyr_data” is the data itself):

[code]
– onEvent listener for the tableView
local function onRowTouch( event )
local row = event.target
local rowGroup = event.view

if event.phase == “press” then

if not row.isCategory and row.title then
row.title.text = plyr_dat[event.index]
row.title:setReferencePoint( display.CenterLeftReferencePoint )
row.title:setTextColor( 100,100,255 )
row.title.x = 200
end

elseif event.phase == “release” then

if not row.isCategory then
row.reRender = true
print( plyr_dat[event.index])

end
end

return true
end

– onRender listener for the tableView
local function onRowRender( event )
local row = event.target
local rowGroup = event.view
local textFunction = display.newRetinaText
if row.isCategory then textFunction = display.newEmbossedText; end

row.title = textFunction( cat[event.index], 12, 0, native.systemFontBold, 16 )
row.title:setReferencePoint( display.CenterLeftReferencePoint )
row.title.y = row.height * 0.5

if not row.isCategory then
row.title.x = 15
row.title:setTextColor( 0 )
end

– must insert everything into event.view:
rowGroup:insert( row.title )
end

– Add 6 rows, and two categories to the tableView:
for i=1,6 do
local rowHeight, rowColor, lineColor, isCategory

– insert the row into the tableView widget
list:insertRow{
onEvent=onRowTouch,
onRender=onRowRender,
height=rowHeight,
isCategory=isCategory,
rowColor=rowColor,
lineColor=lineColor
}
end

end
[/code] [import]uid: 95689 topic_id: 18896 reply_id: 73109[/import]

It’s not very clear what you’re trying to do…

It sounds like:

  1. You only have six rows total
  2. Every row is not a category
  3. Therefore every row uses retina text
  4. Each row prints the contents of cat[1 to 6]
  5. On Press, nothing happens

During the for loop you need to give some sort of instruction as to what is a category and what is not.

-- Some people make it simple.  
if i = 3 then  
 isCategory = true  
else  
 isCategory = false  
end  
  
-- But maybe you want to load this from an array.  
-- (Somewhere else)  
myArray = {}  
myArray[1] = {data=1234, category=true}  
-- (in the loop)  
isCategory = myArray[i].category  

Without making that designation it’s going to set one or the other. Or maybe just error out… [import]uid: 41884 topic_id: 18896 reply_id: 73143[/import]

Richard,

Let me see if I can explain:

two arrays A{} and B{}

One has the categories (not to be confused with “isCategory” parameter from Corona) I want to display the other has the data. The widget code demo only allows me to display one or the other. What I need is to display both, each with its on data on same row.

Kind of what you mentioned:

C = {A[1]B[1],A[2]B[2},…}

But how do I get something like “C” above? I looked at concatenate but it does this C = {A[1],…A[6],B[1],…B[6]} and that’s not what I need. [import]uid: 95689 topic_id: 18896 reply_id: 73164[/import]

I guess the problem is I don’t have any concrete idea of what you want to make beyond that really obfuscated example.

concatenate works really well for text.

[code]
table = {}
table[1] = “lobster”
table[2] = “oyster”
myTextObject.text = table[1]…", “…table[2]…”, oh and then some fish please."
– “lobster, oyster, oh and then some fish please.”

You can also concatenate existing stuff.
myTextObject.text = myTextObject.text…" Uh, I forgot this line."
– lobster, oyster, oh and then some fish please. Uh, I forgot this line."[/code]

If you’re talking about concatenating code it becomes a bit more difficult and there are different approaches based on what you need. But the basics above still work in other tables.

local somenumber = 3 table[3] = "shrimp"..somenumber print(table[3]) -- "shrimp3"

So using these principles it’s pretty easy to either concatenate text into the title, or simply add additional text and inserting it into rowgroup. I pretty commonly have subtitles and other text bits within my tableView…is that what you’re talking about?

The only other thing I can think of that you might be talking about is that you want to set a very specific row order, interspersing A and B rows… [import]uid: 41884 topic_id: 18896 reply_id: 73181[/import]

Richard,

Sorry I could not explain myself, but you provide the correct ideas for me to try. I quess I was trying to make it harder than what it was. Here is how I did it (with your help !). It works now:

--   
-- combine both catagory and player data   
--  
 C = cat[event.index].." "..plyr\_dat[event.index]  
 row.title = textFunction( C, 12, 0, native.systemFontBold, 16 )  
 row.title:setReferencePoint( display.CenterLeftReferencePoint )  
 row.title.y = row.height \* 0.5  

Thanks again

[import]uid: 95689 topic_id: 18896 reply_id: 73291[/import]