android - How to create dynamically objects (textFields from native library), and add event to them -
i've dynamically created textfield using corona, can't add events these objects, because need store information of textfield in table.
i used in c# using 1 event , asked focus of textbox, in case don't know do. property focus textfield doesn't exist (you can set focus, can't ask state).
on other hand, tried create table functions, , pass these functions addeventlistener
of textfield, does't work.
i appreciate advice solve problem, thanks!!!!
local widget=require("widget") local native=require("native") local listtextfields={} local positiony=display.contentcentery --handle textfield local function textfieldhandle( event ) if ( event.phase == "began" ) elseif ( event.phase == "ended" or event.phase == "submitted" ) --??? elseif ( event.phase == "editing" ) --??? end end --this button's event local function buttonevent_1 (event) listtextfields[#listtextfield+1]=native.newtextfield{ x=display.contentcenterx, y=positiony, width=100, height=50 } positiony=positiony+70 --this main problem listextfields[#listtextfields]:addeventlistener("userinput",textfieldhandle) --but in case don't how build handle textfield, cause don't textfield have focus. end -- button local propertiesbutton = { left = display.contentcenterx, top = display.contentcentery - display.contentheight/2, width = 80, height = 80 , label= "add", defaultfile = "defaultbutton.png", overfile = "overbutton.png", onpress=buttonevent_1 } button1 = widget.newbutton(propertiesbutton)
the property focus textfield doesn't exist (you can set focus, can't ask state).
sure can. there way know textfield has focus .. first let me add display.newtext() testing .. @ top before eventhandlers
local test = display.newtext( " ", 100, 100, nil, 20 )
now add id property each of textfields, after creation of textfield add ..
listtextfields[#listtextfield+1]=native.newtextfield{ x=display.contentcenterx, y=positiony, width=100, height=50 } listtextfields[#listtextfields].id = #listtextfields
to determine textfield has focus .. can use event.phase == "began" inside eventhandler .. can access textfield event.target ... display id of textfield focus ..
local function textfieldhandle( event ) if ( event.phase == "began" ) test.text = "the focus on textfield # " .. event.target.id end end
Comments
Post a Comment