Ariel Córdova Sewer Ariel Córdova Sewer - 9 months ago 45
Android Question

How can I access, to the row content in a TableView, by clicking the row

This is my problem, I'm trying to show the content of a selected row in a TableView, when I clicked.

In the onRowRender I add the rows by this way,

local function onRowRender( event )
local row = event.row
local myText = ""
local myText = display.newText(row,"Text to show",150,row.contentHeight/2,native.systemFontBold,30 )

In the onRowTouch event I have tried this,

local function onRowTouchTable( event )
print(menuPedidos._view._rows[row.index]) //it return a table, I assumed the row selected
print(menuPedidos._view._rows[row.index].mytext) //it return nil

And what I need, is the text saved in the object mytext

I will appreciate any help, thank you

Answer Source

I think you should store your data in separate variable, pass it in params in insertRow and set row's id also in insertRow to reference to them later.


for i = 1, #myData do
      rowHeight = 60,
      id = i,
      isCategory = false,
      rowColor = { 1, 1, 1 },
      lineColor = { 0.90, 0.90, 0.90 },
      params = {
         name = myData[i].name,
         phone = myData[i].phone

So in onRowTouchTable you can do something like that

local function onRowTouchTable(event) 
   local row =
   local id = row.index -- or I'm not sure


More information you find on Corona blog. Also, you can see youtube video Corona University - Displaying Database Data Using TableView Widgets.