Hi,
I have a button in each row of a tableView. When the user completes a taks, he/she clicks on the buttons.
For onRowTouch, the listening function can use the target.index
Like so
local function RowTouch(e) local row = e.target print(row.index) end
and will print out the index (ignore phases for now).
When I am rendering my tableview, I am adding the button to each row rendered -that is not a category.
Like so.
if (row.isCategory == false) then local btncheck = widget.newButton({ label = "check", left = display.contentWidth-80, width = 75, onEvent = btncheck\_clicked }) row:insert(btncheck) end
so - in my function btncheck_clicked(), how do I get the current row?
Thanks.
Herb
This is not a direct answer, but if you want to dig into the guts of widgets you can look at the code here:
http://github.com/coronalabs/framework-widget
Hi,
I have a button in each row of a tableView. When the user completes a taks, he/she clicks on the buttons.
For onRowTouch, the listening function can use the target.index
Like so
local function RowTouch(e) local row = e.target print(row.index) end
and will print out the index (ignore phases for now).
When I am rendering my tableview, I am adding the button to each row rendered -that is not a category.
Like so.
if (row.isCategory == false) then local btncheck = widget.newButton({ label = “check”, left = display.contentWidth-80, width = 75, onEvent = btncheck_clicked }) row:insert(btncheck) end
so - in my function btncheck_clicked(), how do I get the current row?
Thanks.
Herb
I would put this inside row render and do btncheck.index = row.id( I am pretty (99%) sure that is how you get row number). That is what I did in my game.
Hi RoamingGamer,
I appreciate the feedback, and have looked through the documents.
Unfortunately, what I am looking for is a way to capture the row index (or any information I have saved via Row:insert()) with a control on the row itself.
Something very similar to the onDisclosure button in IOS.
I am surprised that there is not a simple way to know which row the control is on.
I will keep digging, but again, appreciate the help.
Thanks.
Herb
Hi Scottrules44,
That worked!
Thanks.
In case anyone needs this in the future.
In the onRender, I set the buttons ID to the row.index
row.btn = widget.newButton({ id = row.index, width = 60, onEvent = showclicked, }) row:insert(row.btn)
in the event function
local function showclicked(e) print(e.target.id ) end
ps - codes a little different from the original post.
This is not a direct answer, but if you want to dig into the guts of widgets you can look at the code here:
http://github.com/coronalabs/framework-widget
Hi,
I have a button in each row of a tableView. When the user completes a taks, he/she clicks on the buttons.
For onRowTouch, the listening function can use the target.index
Like so
local function RowTouch(e) local row = e.target print(row.index) end
and will print out the index (ignore phases for now).
When I am rendering my tableview, I am adding the button to each row rendered -that is not a category.
Like so.
if (row.isCategory == false) then local btncheck = widget.newButton({ label = “check”, left = display.contentWidth-80, width = 75, onEvent = btncheck_clicked }) row:insert(btncheck) end
so - in my function btncheck_clicked(), how do I get the current row?
Thanks.
Herb
I would put this inside row render and do btncheck.index = row.id( I am pretty (99%) sure that is how you get row number). That is what I did in my game.
Hi RoamingGamer,
I appreciate the feedback, and have looked through the documents.
Unfortunately, what I am looking for is a way to capture the row index (or any information I have saved via Row:insert()) with a control on the row itself.
Something very similar to the onDisclosure button in IOS.
I am surprised that there is not a simple way to know which row the control is on.
I will keep digging, but again, appreciate the help.
Thanks.
Herb
Hi Scottrules44,
That worked!
Thanks.
In case anyone needs this in the future.
In the onRender, I set the buttons ID to the row.index
row.btn = widget.newButton({ id = row.index, width = 60, onEvent = showclicked, }) row:insert(row.btn)
in the event function
local function showclicked(e) print(e.target.id ) end
ps - codes a little different from the original post.