Placing button widget inside tableview widget

Is it possible to place a button widget in each row of a tableview widget and the capture the button press before capturing the row press?

I can get the button in the row with now problem, but can seem to get the button press event captured - it captures the onTouch for the row and then goes on.

Any ideas?

Thanks,
Ken [import]uid: 113197 topic_id: 34114 reply_id: 334114[/import]

Are you returning true from your event listener? I know there was a bug in the old UI lib where oing that did not help and you would have to also catch the touch event on the button object as well. [import]uid: 8271 topic_id: 34114 reply_id: 135644[/import]

I was not. Put that in the event listener for the button and it works like a charm!

Thanks!

Now I just have to figure out how to detect which button was pressed(from which row) :slight_smile: [import]uid: 113197 topic_id: 34114 reply_id: 135647[/import]

If you set the id for each button you create then it should be possible to track which button was pressed in a Button Handler like onButtonEvent.

[code]
local onButtonEvent = function (event )
local id = event.id
if event.phase == “release” then
if id ==“btn001” then
– do something
print( “You pressed and released a button!” )
end
end
end

local myButton = widget.newButton{
id = “btn001”,
left = 100,
top = 200,
label = “Widget Button”,
width = 150, height = 28,
cornerRadius = 8,
onEvent = onButtonEvent
}

[/code] [import]uid: 98060 topic_id: 34114 reply_id: 135680[/import]

When you create your button in the onRowRender() function, simply assign the row’s index value to the button. Remember you can add any variable you like to an object:

myButton.rowIndex = index

Then in the handler, event.target will be the button touched and event.target.rowIndex will be the row’s index that you set.
[import]uid: 199310 topic_id: 34114 reply_id: 135685[/import]

Thanks. I had come up with a different way, but hadn’t remembered that event.target got me the object which fired the event. This is much cleaner than what I had done as below

function onPress(event,idx) if event.phase == "release" then system.openURL ("tel:" .. listDLOffices[idx].phone) end end local phoneButton = widget.newButton{ id = "btn003", left = row.textObj6.x, top = row.textObj6.y, width = row.textObj6.width, height = row.textObj6.height, onEvent = function(event) onPress(event,idx) return true end, default="refreshbutton.png" } rowGroup:insert(phoneButton) [import]uid: 113197 topic_id: 34114 reply_id: 135754[/import]

Are you returning true from your event listener? I know there was a bug in the old UI lib where oing that did not help and you would have to also catch the touch event on the button object as well. [import]uid: 8271 topic_id: 34114 reply_id: 135644[/import]

I was not. Put that in the event listener for the button and it works like a charm!

Thanks!

Now I just have to figure out how to detect which button was pressed(from which row) :slight_smile: [import]uid: 113197 topic_id: 34114 reply_id: 135647[/import]

If you set the id for each button you create then it should be possible to track which button was pressed in a Button Handler like onButtonEvent.

[code]
local onButtonEvent = function (event )
local id = event.id
if event.phase == “release” then
if id ==“btn001” then
– do something
print( “You pressed and released a button!” )
end
end
end

local myButton = widget.newButton{
id = “btn001”,
left = 100,
top = 200,
label = “Widget Button”,
width = 150, height = 28,
cornerRadius = 8,
onEvent = onButtonEvent
}

[/code] [import]uid: 98060 topic_id: 34114 reply_id: 135680[/import]

When you create your button in the onRowRender() function, simply assign the row’s index value to the button. Remember you can add any variable you like to an object:

myButton.rowIndex = index

Then in the handler, event.target will be the button touched and event.target.rowIndex will be the row’s index that you set.
[import]uid: 199310 topic_id: 34114 reply_id: 135685[/import]

Thanks. I had come up with a different way, but hadn’t remembered that event.target got me the object which fired the event. This is much cleaner than what I had done as below

function onPress(event,idx) if event.phase == "release" then system.openURL ("tel:" .. listDLOffices[idx].phone) end end local phoneButton = widget.newButton{ id = "btn003", left = row.textObj6.x, top = row.textObj6.y, width = row.textObj6.width, height = row.textObj6.height, onEvent = function(event) onPress(event,idx) return true end, default="refreshbutton.png" } rowGroup:insert(phoneButton) [import]uid: 113197 topic_id: 34114 reply_id: 135754[/import]