Nested event listeners

I have a table view that has a button (and some other stuff) on each row.

When the user taps a button in one of the rows, I want to do one thing; when they tap a row outside the button, I want to do another thing.

The problem is that when I tap a button on a row, both event listeners fire - the button listener first, and the row listener second.

I want the button listener (only) to fire when the button is tapped, and the row listener (only) to fire when the row is tapped outside of the button on that row.


local function btnRowListener (event)

print (“exiting btnRowListener”)

return true

end

local function rowRender (event)

local row = event.row

local rowHeight = row.height

local rowWidth = row.width

local btnRow = widget.newSwitch {

   x = 10, y = row.height / 2,

   style = “checkbox”,

   onPress = btnRowListener

}

row:insert(btnRow)

local options_name = {parent = row, text = row.params.name, x = 40, y = row.height / 2, font = native.systemFont, fontSize = 14}

row.name = display.newText(options_name)

end

local function rowTouchListener (event)

local row = event.row

print ("exiting rowTouchListener ")

end

tv = widget.newTableView 

{

x = dsp.centerX, y = dsp.centerY + (dsp.navBarHeight / 2),

width = dsp.width, height = dsp.height - dsp.navBarHeight,

onRowRender = rowRender,

onRowTouch = rowTouchListener

}

Further observations: the first time through, the button acts correctly (i.e., the button listener fires and the row listener does not).

If, however, the user taps the row (not the button), the storyboard goes to another scene; then, when the user taps the back button to return to the list view, THEN the double listener happens (i.e., button listener fires, followed by the row listener).

The button listener is set during rowRender; the row listener is set when declaring the tableView, during createScene.

It may be that there is something about enterScene vs. createScene that is causing the trouble?

Further observations: the first time through, the button acts correctly (i.e., the button listener fires and the row listener does not).

If, however, the user taps the row (not the button), the storyboard goes to another scene; then, when the user taps the back button to return to the list view, THEN the double listener happens (i.e., button listener fires, followed by the row listener).

The button listener is set during rowRender; the row listener is set when declaring the tableView, during createScene.

It may be that there is something about enterScene vs. createScene that is causing the trouble?