Hi Brent,
Thank you for the help.
I tried to put the handler function outside of onRowRender, though since during the ‘submitted’ phase the handler is supposed to set the ‘showInd’ text property to the user input I get an error: ‘showInd’ is a child of the row so if the handler is outside of onRowRender it can’t access ‘showInd’.
Please correct me if I’m wrong.
Anyway I tried again by keeping the textfiled Handler inside of onRowRender and used addEventlistener as you suggested. Now the handler produces the effect I want: ‘showInd.text’ gets set to the textfield input and the textfield object removes itself. The problem now is that when I scroll down the tableview and the showInd object goes offscreen, when it comes back it’s set to the its original value and the textfield is there again! Basically its like the textfield handler function got its effect nullified. How is that possible?
Here’s the new piece of code:
function onRowRender( event ) local row = event.row local rowHeight = row.contentHeight local rowWidth = row.contentWidth local showInd = display.newText( row, row.index, 0, 0, nil, 16 ) showInd.anchorX = 0 showInd.x = 8 showInd.y = rowHeight / 10 showInd:setFillColor( 0.8 ) showInd.alpha = 0.7 local inputName = native.newTextField( 0, 0 , 100, 16 ) row:insert (inputName) inputName.anchorX = 0.5 inputName.x = rowWidth / 2 inputName.y = rowHeight \* 0.1 inputName.inputType = "default" inputName:setTextColor( 1, 1, 1 ) inputName.hasBackground = false inputName.align = "center" inputName.alpha = .8 local function inHandler (event) local length = string.len( inputName.text ) if (event.phase == "began") then elseif (event.phase == "editing") then print ("editing " .. event.target.text) elseif (event.phase == "ended") then print ("ended " .. event.target.text) self.text = "" elseif (event.phase == "submitted") then print ("submitted " .. event.target.text) if (length \> 0) then showInd.text = event.target.text ---- here set the text of the object to the user input native.setKeyboardFocus (nil) inputName:removeSelf( ) ---- here the textfield gets removed. These two latter commands get ----'nullified' when I scroll the row off and back on screen else native.setKeyboardFocus (nil) end end end inputName:addEventListener( "userInput", inHandler ) end
I guess the rows are re-rendering when they get back on-screen, but how to keep persistency on the effect of the hanlder function? Beside I have another text object in the row that gets modified by a button, but in its case the changes sticks to it even if it goes offscreen and back…
Thank you.