android - How to setup onFocusChangeListener() on a dynamically created set of editTexts? -
i have code in inflate linearlayout containing 3 edittexts everytime edittext of previous linealayout loses focus. want have onfocuschangelistener on recent created edittexts only. instead, onfocuschangelistener called when the first linearlayout loses focus , not rest of others.
protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.sale_purchase_vouch); no=0; for(int i=0;i<30;i++) flag[i]=true; save=(button)findviewbyid(r.id.save); save.settext("confirm purchase"); layoutinflater l=getlayoutinflater(); container=(linearlayout)findviewbyid(r.id.container); row[no]=(linearlayout)l.inflate(r.layout.row, container); items[no]=(autocompletetextview)row[no].findviewbyid(r.id.item); quants[no]=(edittext)row[no].findviewbyid(r.id.quant); rates[no]=(edittext)row[no].findviewbyid(r.id.rate); quants[no].setonfocuschangelistener(this); flag[no]=false; } @override public void onfocuschange(view arg0, boolean arg1) { // todo auto-generated method stub if(flag[no+1]==true){ if(arg1==false){ no++; layoutinflater g=getlayoutinflater(); row[no]=(linearlayout)g.inflate(r.layout.row, container); items[no]=(autocompletetextview)row[no].findviewbyid(r.id.item); quants[no]=(edittext)row[no].findviewbyid(r.id.quant); rates[no]=(edittext)row[no].findviewbyid(r.id.rate); log.d("detection", "row "+ no+ arg0.getid()); } } }
i created array of boolean know whether last edittext had created new linearlayout(listened onfocuschangelistener). help!!!
you need extend edittext
class create own type of view
might want have inner class implement view.onfocuschangelistener , public
method can setup listener instance of inner class using instance of newly created type.
Comments
Post a Comment