TableView: no event.x?

Hi, I’m using the lovely TableView control in an Android project. My rows have a checkbox on the right for users to check off items. Sometimes the TableView “tap” and the checkbox “press” events both trigger. I need the tap event to switch to a detail view and the checkbox to complete the item. I’d like to ignore the tap event after a certain x range where my checkbox lives. However, there doesn’t seem to be an event.x for a TableView, am I correct in this isn’t supported yet? If not, does anyone have a strategy to deal with determining which event to process in this case?

Thanks,

Jason

Have you tried to set “return true” in your check box touch handler? Theoretically touches should stop propagating then.

Hi Jon - thanks much for the fast reply.  I just added this to my event handler (return true after the onPress event is fired).  Still getting the same behavior.  It looks like I’ll have to manually detect the events and determine which gets fired based on sequence and timing between the events.  Thanks for the feedback and much interested if there are other approaches.

Thanks,

Jason

I had a tableview from previous test so I tried your case. My example has a strange problem. If you touch checkbox first the touch does not leak through. But if you touch a row and then the checkbox the touch goes through.

Can someone shed some light on this? 

This is code to reproduce:

[lua]

display.setStatusBar( display.HiddenStatusBar )

local widget = require( “widget” )

local function onRowTouch( event )

    if event.phase == ‘tap’ then

        print (“Row touch”)

    end

end

local function checkBoxEvent(event)

    

    if event.phase == “began” then

        print(‘Checkbox touch’)

    end

    return true

    

end

local function onRowRender( event )

    local row = event.row

    local rowTitle = display.newText( row, "TEST " … row.index, 0, 0, nil, 14 )

    rowTitle.x = display.contentWidth / 2

    rowTitle.y = row.contentHeight * 0.5

    rowTitle:setTextColor( 0, 0, 0 )

    

    local check = display.newRect(row, 0, 0, 10, 10)

    check.x = 10

    check.y = row.contentHeight * 0.5

    check.strokeWidth = 2

    check:setFillColor(140, 140, 140)

    check:setStrokeColor(180, 180, 180)

    check : addEventListener(“touch”, checkBoxEvent)

    

end

local tableView = widget.newTableView {

    width = display.contentWidth, 

    height = display.contentHeight,

    onRowRender = onRowRender,

    onRowTouch = onRowTouch,

}

tableView:insertRow{rowHeight = 40}

tableView:insertRow{rowHeight = 40}

tableView:insertRow{rowHeight = 40}

[/lua]

Just to close the loop on this, I was able to resolve this issue by implementing a timer:

function checkboxPressEvent( event ) lastEventFired = os.clock() -- implementation end function rowTouch( event ) if event.phase == "tap" and (lastEventFired + 0.5 \< os.clock()) then storyboard.gotoScene( "goaldetail" ) end end

Thanks for helping review this issue Jon, much appreciated.

Jason

Have you tried to set “return true” in your check box touch handler? Theoretically touches should stop propagating then.

Hi Jon - thanks much for the fast reply.  I just added this to my event handler (return true after the onPress event is fired).  Still getting the same behavior.  It looks like I’ll have to manually detect the events and determine which gets fired based on sequence and timing between the events.  Thanks for the feedback and much interested if there are other approaches.

Thanks,

Jason

I had a tableview from previous test so I tried your case. My example has a strange problem. If you touch checkbox first the touch does not leak through. But if you touch a row and then the checkbox the touch goes through.

Can someone shed some light on this? 

This is code to reproduce:

[lua]

display.setStatusBar( display.HiddenStatusBar )

local widget = require( “widget” )

local function onRowTouch( event )

    if event.phase == ‘tap’ then

        print (“Row touch”)

    end

end

local function checkBoxEvent(event)

    

    if event.phase == “began” then

        print(‘Checkbox touch’)

    end

    return true

    

end

local function onRowRender( event )

    local row = event.row

    local rowTitle = display.newText( row, "TEST " … row.index, 0, 0, nil, 14 )

    rowTitle.x = display.contentWidth / 2

    rowTitle.y = row.contentHeight * 0.5

    rowTitle:setTextColor( 0, 0, 0 )

    

    local check = display.newRect(row, 0, 0, 10, 10)

    check.x = 10

    check.y = row.contentHeight * 0.5

    check.strokeWidth = 2

    check:setFillColor(140, 140, 140)

    check:setStrokeColor(180, 180, 180)

    check : addEventListener(“touch”, checkBoxEvent)

    

end

local tableView = widget.newTableView {

    width = display.contentWidth, 

    height = display.contentHeight,

    onRowRender = onRowRender,

    onRowTouch = onRowTouch,

}

tableView:insertRow{rowHeight = 40}

tableView:insertRow{rowHeight = 40}

tableView:insertRow{rowHeight = 40}

[/lua]

Just to close the loop on this, I was able to resolve this issue by implementing a timer:

function checkboxPressEvent( event ) lastEventFired = os.clock() -- implementation end function rowTouch( event ) if event.phase == "tap" and (lastEventFired + 0.5 \< os.clock()) then storyboard.gotoScene( "goaldetail" ) end end

Thanks for helping review this issue Jon, much appreciated.

Jason