TableView highlight row selected

As I said above: Row colors should not be set at the time of clicking on it, and at the moment of creating a row!

Look at this easy sample especially on the line 32 - 42:

local widget = require( "widget" ) local function onRowRender( event ) local phase = event.phase local row = event.row local rowTitle = display.newText( row, "Row " .. row.index, 0, 0, nil, 30 ) rowTitle.x = rowTitle.width / 2 + 25 rowTitle.y = row.contentHeight \* 0.5 rowTitle:setTextColor( 0, 0, 0 ) end local function onRowTouch( event ) local phase = event.phase if "press" == phase then print( "Touched row:", event.target.index ) end end local tableView = widget.newTableView { top = 100, width = W, height = H, maskFile = "assets/mask-320x366.png", listener = tableViewListener, onRowRender = onRowRender, onRowTouch = onRowTouch, } for i = 1, 20 do tableView:insertRow { rowHeight = 75, rowColor = { default = { 232, 232, 232 }, over = {255, 100, 100} -- color on click }, lineColor = { 100, 100, 100 }, } end

if I understand you correctly

I don’t think you do! ‘over’ sets the row highlighted when it’s touched. But when the touch ends the color goes back to default. I need the row to stay highlighted until another row is touched.

Why don’t you set the fill color of the background of the row in the onRowTouch() function.  I would add my own background object (perhaps a display.newRect()) in onRowRender() so I have an object to color in onRowTouch().

All genius is simple (=

local function onRowTouch( event ) local phase = event.phase local row = event.target if "press" == phase then for i = 1, tableView:getNumRows() do if i == row.index then tableView.\_view.\_rows[i].\_rowColor.default = { 1, 100/255, 100/255 } else tableView.\_view.\_rows[i].\_rowColor.default = { 232/255, 232/255, 232/255 } end; end tableView:reloadData() end

tableView:reloadData() did the trick! Thanks all!

Hi,
I’m having the same problem, I pasted my code below. 

local function onRowTouchGroup( event ) local phase = event.phase local row = event.target if "release" == phase then for i = 1, groupList:getNumRows() do local tmpRow = groupList:getRowAtIndex(i) tmpRow:setRowColor{ default = { 80/255 }, over = { 1, 113/255, 0 } } end row:setRowColor{ default = { 1, 113/255, 0 }, over = { 1, 113/255, 0 } } studentList:deleteAllRows() selectedGroup = row.index for i = 1, #connector.groups[row.index].students do studentList:insertRow{ rowHeight = 60, } end end end

When I click a row it is highlighted and then turns back to the default colour. but when I click on it two times fast it turns orange. When i click another item it also turns orange but the previous one isn’t being changed to the normal color.

[quote=“rick.slot,post:27,topic:319256”]

Hi,
I’m having the same problem, I pasted my code below. 

local function onRowTouchGroup( event ) local phase = event.phase local row = event.target if "release" == phase then for i = 1, groupList:getNumRows() do local tmpRow = groupList:getRowAtIndex(i) tmpRow:setRowColor{ default = { 80/255 }, over = { 1, 113/255, 0 } } end row:setRowColor{ default = { 1, 113/255, 0 }, over = { 1, 113/255, 0 } } studentList:deleteAllRows() selectedGroup = row.index for i = 1, #connector.groups[row.index].students do studentList:insertRow{ rowHeight = 60, } end end end

When I click a row it is highlighted and then turns back to the default colour. but when I click on it two times fast it turns orange. When i click another item it also turns orange but the previous one isn’t being changed to the normal color. [/quote]

Tell me what you want to do?

I want to keep one row highlighted when it is clicked. It must be deselected when i click another row, and then that row needs to be highlighted!

As I said above: Row colors should not be set at the time of clicking on it, and at the moment of creating a row!

Look at this easy sample especially on the line 32 - 42:

local widget = require( "widget" ) local function onRowRender( event ) local phase = event.phase local row = event.row local rowTitle = display.newText( row, "Row " .. row.index, 0, 0, nil, 30 ) rowTitle.x = rowTitle.width / 2 + 25 rowTitle.y = row.contentHeight \* 0.5 rowTitle:setTextColor( 0, 0, 0 ) end local function onRowTouch( event ) local phase = event.phase if "press" == phase then print( "Touched row:", event.target.index ) end end local tableView = widget.newTableView { top = 100, width = W, height = H, maskFile = "assets/mask-320x366.png", listener = tableViewListener, onRowRender = onRowRender, onRowTouch = onRowTouch, } for i = 1, 20 do tableView:insertRow { rowHeight = 75, rowColor = { default = { 232, 232, 232 }, over = {255, 100, 100} -- color on click }, lineColor = { 100, 100, 100 }, } end

if I understand you correctly

I don’t think you do! ‘over’ sets the row highlighted when it’s touched. But when the touch ends the color goes back to default. I need the row to stay highlighted until another row is touched.

Why don’t you set the fill color of the background of the row in the onRowTouch() function.  I would add my own background object (perhaps a display.newRect()) in onRowRender() so I have an object to color in onRowTouch().

All genius is simple (=

local function onRowTouch( event ) local phase = event.phase local row = event.target if "press" == phase then for i = 1, tableView:getNumRows() do if i == row.index then tableView.\_view.\_rows[i].\_rowColor.default = { 1, 100/255, 100/255 } else tableView.\_view.\_rows[i].\_rowColor.default = { 232/255, 232/255, 232/255 } end; end tableView:reloadData() end

tableView:reloadData() did the trick! Thanks all!

Kind of old topic, but because I ended up here, I shall complete the last bit of code by adding that reloadData() is essential if you want to change the color but also you can use :

row:setRowColor( default = { 232 / 255 , 232 / 255 , 232 / 255 }, over = {255/ 255, 100/ 255, 100/ 255} )

which is better than 

row.\_rowColor.default = { 1, 100/255, 100/255 }

Kind of old topic, but because I ended up here, I shall complete the last bit of code by adding that reloadData() is essential if you want to change the color but also you can use :

row:setRowColor( default = { 232 / 255 , 232 / 255 , 232 / 255 }, over = {255/ 255, 100/ 255, 100/ 255} )

which is better than 

row.\_rowColor.default = { 1, 100/255, 100/255 }