android - First and last EditText in ListView is showing the same value -
when showing in view, value enter last edittext
being shown in both first , last edittext
boxes if scroll past first edittext
box. when saving value database, saving last edittext
value expected however.
what causing behaviour? here complete code:
package com.example.expensemanager1; import java.util.list; import android.app.activity; import android.content.context; import android.graphics.color; import android.text.editable; import android.text.textwatcher; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.view.view.onfocuschangelistener; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.checkbox; import android.widget.compoundbutton; import android.widget.edittext; import android.widget.linearlayout; import android.widget.textview; import android.widget.toast; public class interactivearrayadapter extends arrayadapter<model> { private final list<model> list; private final activity context; final int i; layoutinflater minflater; public interactivearrayadapter(activity context, list<model> list) { super(context, r.layout.spared_list_row, list); this.context = context; this.list = list; i=list.size(); notifydatasetchanged(); } static class viewholder { protected textview membname; protected edittext membamount; } public class mytextwatcher implements textwatcher { private edittext edittext; model elemente; public mytextwatcher(edittext edittext, model m) { this.edittext = edittext; this.elemente = m; } @override public void aftertextchanged(editable s) { // todo auto-generated method stub log.d("test", "in aftertextchanged"); edittext.setfocusable(true); string ssss= s.tostring(); if(edittext.gettext().tostring().length()>0) list.get((integer)edittext.gettag()).setamount(double.parsedouble(s.tostring())); else list.get((integer)edittext.gettag()).setamount(0); double sum=0.0; (int j=0; j<i ; j++) { model m1= list.get(j); sum += m1.getamount(); } log.d("test", "sum" +sum ); double balance = new_spared_list.gettextview(); log.d("test", "balance = "+ balance); sum = balance - sum; new_spared_list.setx(sum); log.d("test", "sum" +sum ); } @override public void beforetextchanged(charsequence s, int start, int count, int after) { // todo auto-generated method stub } @override public void ontextchanged(charsequence s, int start, int before, int count) { } } @override public view getview(int position, view convertview, viewgroup parent) { view view = null; viewholder viewholder = new viewholder(); if (convertview == null) { final model elemente = list.get(position); layoutinflater inflator = context.getlayoutinflater(); convertview = inflator.inflate(r.layout.spared_list_row, null); viewholder.membname = (textview) convertview.findviewbyid(r.id.memberstextview2); viewholder.membamount = (edittext) convertview.findviewbyid(r.id.amount); final viewholder holder = viewholder; viewholder.membamount.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //do linearlayout parent = (linearlayout) v.getparent(); edittext membamount = (edittext) parent.findviewbyid(r.id.amount); membamount.setfocusable(true); membamount.setfocusableintouchmode(true); membamount.requestfocus(); } }); viewholder.membamount.addtextchangedlistener(new mytextwatcher(viewholder.membamount, (model) viewholder.membamount.gettag())); convertview.settag(viewholder); convertview.settag(r.id.memberstextview2, viewholder.membname); convertview.settag(r.id.amount, viewholder.membamount); // viewholder.membamount.settag(list.get(position)); // viewholder.membamount.sethint(string.valueof((list.get(position).getamount()))); } else { viewholder = (viewholder) convertview.gettag(); ((viewholder) convertview.gettag()).membamount.settag(list.get(position)); } viewholder.membamount.settag(position); if(position % 2 == 0){ convertview.setbackgroundcolor(color.rgb(231, 247, 253)); } // viewholder.membamount.settag(list.get(position)); viewholder.membamount.sethint(string.valueof(list.get(position).getamount())); viewholder.membname.settext(list.get(position).getname()); return convertview; } }
at end of getview(), should change text in membamount; otherwise, if reuses convertview, keeps previous text.
viewholder.membamount.settext(list.get(position).getamount());
Comments
Post a Comment