Question

In my corona project i want to show textfield in table row.Here the code ,its shows only one textfield, i want to show the textfield in data available rows.

local function onRowRender( event )
local phase = event.phase
local row = event.row

local itemObj = GetItemDetails(row.index);

local txt = itemObj.itemName;
if(#txt > 25) then
    txt = string.sub(txt,1,25);
    txt = txt.."..";
end

local rowTitle = display.newText( row, "\t"..txt, 0, 0, "impact", 14 )
if(deviceName == "iPhone" or deviceName == "iPad") then
    rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )
else
    rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )+15
end
rowTitle.y = row.contentHeight * 0.5
rowTitle:setTextColor(98, 71, 24)

local rowqtytxt=nil; 
if(deviceName == "iPhone" or deviceName == "iPad") then
    rowqtytxt= native.newTextField( 0, 0,32, 32 ,onSubmitted);
    rowqtytxt.x = 125;
    rowqtytxt.hasBackground = false;
    --rowqtytxt:addEventListener( "userInput", textListener )
    rowqtytxt.size = 32;
else
    rowqtytxt = native.newTextField( 0, 0,32, 32 ,onSubmitted);
    rowqtytxt.x = 207;
    rowqtytxt.hasBackground = false;
   -- rowqtytxt:addEventListener( "userInput", textListener )
    rowqtytxt.size = 32;
end

rowqtytxt.y = row.contentHeight * 0.5
rowqtytxt:setTextColor(98, 71, 24)
return true;
end

The above code shows only one text field.Please help to solve this issue

Was it helpful?

Solution

When you say 'data available rows', what do you mean? It seems to me you mean that itemObj will not always have data in it?

If this is the case, then you need to wrap the adding of the text field in an if block:

if(itemObj ~= nil) then
    --Adding textField code
end

Also, this function seems to render a single row. So you would need to wrap it in a for loop. Something like

local i;
--The # means 'length of'
for i=1, #yourDataSource do
    onRowRender(yourItemData)
end

OTHER TIPS

In Corona SDK widget.newTableView's are based on display groups. You cannot insert native.* objects into display groups. Therefore a tableView cannot scroll text fields as part of the rows.

There was a tutorial a couple of weeks ago, where we demoed how to tie a native.newTextField to a display group. http://coronalabs.com/blog/2013/12/03/tutorial-customizing-text-input/

There is a community project that's building a variant of the idea in that tutorial that you could find on the forums.

The idea is to use an enterFrame listener to move the native.newTextField to wherever the display object that it's tied to. However, what will make this not practical for a tableView is that when the tableView scrolls the rows off the screen, they may not get removed correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top