Questions about table widget rows

I finally got a switch added to my table list view as a first column, and a label to the right of that in a second column. The problem I have now is that when the user taps on the switch (a radio button), it get’s selected as it should, but I can’t figure out how to disable all the other radio buttons in that column in the table / list. I thought i’d use a for loop, but I can’t seem to figure out how to loop through the rows, or even, how to tell which row I’m on.

This is being done within the switch’s event, which is inside the rowRender event. [import]uid: 64538 topic_id: 33788 reply_id: 333788[/import]

What I do is loop through all the rows, turn them all off then turn the one back on that I need to. I’ve never used the new switches and such, but looping over your table is pretty easy… something like this:

 for i=1,#myList.content.rows do  
 if myList.content.rows[i].deleteBtn and myList.content.rows[i].deleteBtn.isVisible == true then  
 myList.content.rows[i].deleteBtn.isVisible = false  
 myList.content.rows[i].gameBtn.isVisible = true  
 end  
 end  

In my case I’m simply hiding a simple graphic button and showing back the normal button, but that’s how to iterrate over your list.

event.index should hold the index of the row that was touched so you know which one to turn back on. [import]uid: 199310 topic_id: 33788 reply_id: 134318[/import]

While this looks like exactly what I need, I can’t seem to get Corona to access the status of the radio button (switch) I created inside the rowRender… :frowning:

local mySwitch = widget.newSwitch  
{  
 left = 5,  
 top = 5,  
 width = 20,  
 height = 20,  
 style = "radio",  
 initialSwitchState = false,  
 onPress = onSwitch,  
}  

[import]uid: 64538 topic_id: 33788 reply_id: 134543[/import]

I’m checking with the team to see how to access and change the switch value.
[import]uid: 199310 topic_id: 33788 reply_id: 134550[/import]

What I do is loop through all the rows, turn them all off then turn the one back on that I need to. I’ve never used the new switches and such, but looping over your table is pretty easy… something like this:

 for i=1,#myList.content.rows do  
 if myList.content.rows[i].deleteBtn and myList.content.rows[i].deleteBtn.isVisible == true then  
 myList.content.rows[i].deleteBtn.isVisible = false  
 myList.content.rows[i].gameBtn.isVisible = true  
 end  
 end  

In my case I’m simply hiding a simple graphic button and showing back the normal button, but that’s how to iterrate over your list.

event.index should hold the index of the row that was touched so you know which one to turn back on. [import]uid: 199310 topic_id: 33788 reply_id: 134318[/import]

While this looks like exactly what I need, I can’t seem to get Corona to access the status of the radio button (switch) I created inside the rowRender… :frowning:

local mySwitch = widget.newSwitch  
{  
 left = 5,  
 top = 5,  
 width = 20,  
 height = 20,  
 style = "radio",  
 initialSwitchState = false,  
 onPress = onSwitch,  
}  

[import]uid: 64538 topic_id: 33788 reply_id: 134543[/import]

I’m checking with the team to see how to access and change the switch value.
[import]uid: 199310 topic_id: 33788 reply_id: 134550[/import]

An oversight on my part.

Missing features are:

Grouping of radio buttons (switches).
Being able to set the state of a switch programmatically (ie toggle it on/off)

These have been added to my todo list. [import]uid: 84637 topic_id: 33788 reply_id: 134826[/import]

Ok, so this means there is currently no way to do this? I take it that this also means that there is currently no way to actually access the switch via code? [import]uid: 64538 topic_id: 33788 reply_id: 134828[/import]

You can access it’s state via it’s event listener. As shown in the sample code section of the following api page.

http://docs.coronalabs.com/api/library/widget/newSwitch.html

[import]uid: 84637 topic_id: 33788 reply_id: 134830[/import]

Yes, but how to access it via the row? I’ve tried the following (as well as all sorts of other variations) and keep getting an error…

[lua]local function onSelectedDealer( event )
local switch = event.target
print (dealersTable.content.rows[switch].isOn)
end[/lua]
Runtime error
/Users/dongeraldo/Desktop/AutoRev/addAuto.lua:329: attempt to index field ‘?’ (a nil value)
stack traceback:
[C]: ?
/Users/dongeraldo/Desktop/AutoRev/addAuto.lua:329: in function ‘_onPress’
?: in function <?:391>
?: in function <?:229>
[import]uid: 64538 topic_id: 33788 reply_id: 134834[/import]

Anything I can offer at this stage is just an idea, the plan is to make integration of switches on tableView rows a seamless affair when the tableView’s are remade.

But for now I would do something like this in your onRowRender:

row.switch = switch -- or whatever you have named your switch  

You should then be able to access it via the rows property. As of now I don’t see anywhere, where you have assigned the switch to the row property. [import]uid: 84637 topic_id: 33788 reply_id: 134836[/import]

An oversight on my part.

Missing features are:

Grouping of radio buttons (switches).
Being able to set the state of a switch programmatically (ie toggle it on/off)

These have been added to my todo list. [import]uid: 84637 topic_id: 33788 reply_id: 134826[/import]

Ok, so this means there is currently no way to do this? I take it that this also means that there is currently no way to actually access the switch via code? [import]uid: 64538 topic_id: 33788 reply_id: 134828[/import]

You can access it’s state via it’s event listener. As shown in the sample code section of the following api page.

http://docs.coronalabs.com/api/library/widget/newSwitch.html

[import]uid: 84637 topic_id: 33788 reply_id: 134830[/import]

Yes, but how to access it via the row? I’ve tried the following (as well as all sorts of other variations) and keep getting an error…

[lua]local function onSelectedDealer( event )
local switch = event.target
print (dealersTable.content.rows[switch].isOn)
end[/lua]
Runtime error
/Users/dongeraldo/Desktop/AutoRev/addAuto.lua:329: attempt to index field ‘?’ (a nil value)
stack traceback:
[C]: ?
/Users/dongeraldo/Desktop/AutoRev/addAuto.lua:329: in function ‘_onPress’
?: in function <?:391>
?: in function <?:229>
[import]uid: 64538 topic_id: 33788 reply_id: 134834[/import]

Anything I can offer at this stage is just an idea, the plan is to make integration of switches on tableView rows a seamless affair when the tableView’s are remade.

But for now I would do something like this in your onRowRender:

row.switch = switch -- or whatever you have named your switch  

You should then be able to access it via the rows property. As of now I don’t see anywhere, where you have assigned the switch to the row property. [import]uid: 84637 topic_id: 33788 reply_id: 134836[/import]