android - Multiple TextWatcher added to same EditText in ExpandableListView's group view -
from conclusion of previous post not able track how textwatcher being added multiple times edittext in expandablelistview. arraylist has 2 elements.
the output should list 0 , 1 once called twice.
adapter:
public class expandablelistadapter extends baseexpandablelistadapter { private layoutinflater inflater; private context context; private expandablelistview accordion; private int lastexpandedgroupposition; arraylist<modelobject> mparent; textview textviewlabelgrandtotal; float grandtotal = 0; public expandablelistadapter( context context, arraylist<modelobject> modelobject, expandablelistview accordion, textview textviewlabelgrandtotal) { mparent = modelobject; inflater = layoutinflater.from(context); this.accordion = accordion; this.context=context; this.textviewlabelgrandtotal=textviewlabelgrandtotal; } @override //counts number of group/parent items list knows how many times calls getgroupview() method public int getgroupcount() { return mparent.size(); } @override //counts number of children items list knows how many times calls getchildview() method public int getchildrencount(int i) { return mparent.get(i).childcount; } @override //gets title of each parent/group public object getgroup(int i) { return mparent.get(i).invoice_id; } @override //gets name of each item public object getchild(int i, int i1) { return mparent.get(i).children.get(i1); } @override public long getgroupid(int i) { return i; } @override public long getchildid(int i, int i1) { return i1; } @override public boolean hasstableids() { return true; } @override //in method must set text see parent/group on list public view getgroupview(final int i, boolean b, view view, viewgroup viewgroup) { if (view == null) { view = inflater.inflate(r.layout.sfa_receipt_by_customer_new_receipt_due_invoice_list_item_parent, viewgroup,false); } // set category name tag view can found view later view.settag(getgroup(i).tostring()); checkbox checkboxinv =(checkbox)view.findviewbyid(r.id.checkboxinv); textview textviewlabelinvoice = (textview) view.findviewbyid(r.id.textviewlabelinvoice); textview textviewlabeldate = (textview) view.findviewbyid(r.id.textviewlabeldate); textview textviewdueamt = (textview) view.findviewbyid(r.id.textviewdueamt); textview textviewremainingamt = (textview) view.findviewbyid(r.id.textviewremainingamt); final edittext edittextpaid = (edittext)view.findviewbyid(r.id.edittextpaid); decimalformat df = new decimalformat("#.##"); textviewlabelinvoice.settext(mparent.get(i).invoice_no); textviewlabeldate.settext(mparent.get(i).invoice_date); textviewdueamt.settext(df.format(mparent.get(i).due)); textviewremainingamt.settext(df.format(mparent.get(i).remaining_after_paid)); checkboxinv.setchecked(mparent.get(i).checked); checkboxinv.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { checkbox c = (checkbox) v; system.out.println("===================== check change listerner ============================"); edittextpaid.settext(df.format(mparent.get(i).due)); // edittextpaid.settext(""); system.out.println("===================== check change listerner ============================"); if(c.ischecked() == false) { system.out.println("===================== uncheck change listerner ============================"); edittextpaid.settext(""); system.out.println("===================== uncheck change listerner ============================"); } // notifydatasetchanged(); } }); //enable focus of edit text box edittextpaid.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { system.out.println("on touch listerner"); return false; } }); //disable focus of edittext box edittextpaid.setonfocuschangelistener(new view.onfocuschangelistener() { public void onfocuschange(view v, boolean hasfocus) { system.out.println("on focus change listener"); } }); //re calculate remaining balance amount edittextpaid.addtextchangedlistener(new textwatcher() { { system.out.println("textwatcher initialized..................!! " + + " " + this); } @override public void ontextchanged(charsequence arg0, int arg1, int arg2, int arg3) { system.out.println("on text change"); } @override public void beforetextchanged(charsequence arg0, int arg1, int arg2, int arg3) { system.out.println("before text change"); } @override public void aftertextchanged(editable arg0) { system.out.println("after text change"); } }); //return entire view return view; } @override //in method must set text see children on list public view getchildview(int i, int i1, boolean b, view view, viewgroup viewgroup) { if (view == null) { view = inflater.inflate(r.layout.sfa_receipt_by_customer_new_receipt_due_invoice_list_item_child, viewgroup,false); } system.out.println("inside getchildview()..................!!"); textview textviewlabelreceipt = (textview) view.findviewbyid(r.id.textviewlabelreceipt); textviewlabelreceipt.settext((i1+1)+"."+mparent.get(i).children.get(i1).receipt_no); textview textviewlabeldate = (textview) view.findviewbyid(r.id.textviewlabeldate); textviewlabeldate.settext((i1+1)+"."+mparent.get(i).children.get(i1).receipt_date); textview textviewremainingamt = (textview) view.findviewbyid(r.id.textviewremainingamt); textviewremainingamt.settext((i1+1)+"."+mparent.get(i).children.get(i1).remaining_after_adjusted_amount); textview textviewdueamt = (textview) view.findviewbyid(r.id.textviewdueamt); textviewdueamt.settext((i1+1)+"."+mparent.get(i).children.get(i1).advance_balance); edittext edittextpaid =(edittext)view.findviewbyid(r.id.edittextpaid); return view; } @override public boolean ischildselectable(int i, int i1) { return true; } @override /** * automatically collapse last expanded group */ public void ongroupexpanded(int groupposition) { if(groupposition != lastexpandedgroupposition){ accordion.collapsegroup(lastexpandedgroupposition); } super.ongroupexpanded(groupposition); lastexpandedgroupposition = groupposition; } }
output:
07-30 06:59:28.219: i/system.out(9082): textwatcher initialized..................!! 0 com.example.expandablelistadapter$4@52bf1224 07-30 06:59:28.223: i/system.out(9082): textwatcher initialized..................!! 1 com.example.expandablelistadapter$4@52c09858 07-30 06:59:28.227: i/system.out(9082): textwatcher initialized..................!! 0 com.example.expandablelistadapter$4@52c37d10 07-30 06:59:28.239: i/system.out(9082): textwatcher initialized..................!! 1 com.example.expandablelistadapter$4@52c723ec
solved myself.
placed view[checkbox, edittext, textview] getgroupview() method within viewholder class [which nothing class contain views].
saved using settag() method of "view" object parameter of getgroupview() method if "view" parameter returned null.
retrieved views using gettag() , initialized viewholder object if "view" parameter not null.
Comments
Post a Comment