android - ListView EditTexts values are messed up when scrolling -



android - ListView EditTexts values are messed up when scrolling -

as mentioned in title, listview duplicates edittexts values children after i=10 in loop in code.

public class exerciseadapter extends arrayadapter<exerciseset> { private arraylist<exerciseset> mexercise; private layoutinflater inflater; private list<string> texts = new arraylist<string>(); public exerciseadapter(context context, int textviewresourceid, arraylist<exerciseset> objects) { super(context, textviewresourceid, objects); mexercise = objects; inflater = (layoutinflater) getcontext(). getsystemservice(context.layout_inflater_service); } @override public int getitemviewtype(int position) { if(mexercise.get(position).isset() == false) homecoming 0; else homecoming 1; } @override public int getviewtypecount() { homecoming 2; // 2 types of rows, exercise headers , bodies (sets) } public view getview(final int position, view convertview, viewgroup parent){ view view = convertview; final holder holder; for(int = 0; < mexercise.size(); i++) { texts.add(string.valueof(i)); } if (getitemviewtype(position) == 0) { if (view == null) { view = inflater.inflate(r.layout.item_exercise_header, null); holder = new holder(); holder.exercisetitleview = (textview) view.findviewbyid(r.id.tv_exercice_title); view.settag(holder); } else { holder = (holder) convertview.gettag(); } exerciseset exercise = mexercise.get(position); if (exercise != null) holder.exercisetitleview.settext(exercise.getexercisetitle()); } else { if (view == null) { view = inflater.inflate(r.layout.item_set, null); holder = new holder(); holder.setcounterview = (textview) view.findviewbyid(r.id.tv_set_counter); holder.cbset = (checkbox) view.findviewbyid(r.id.cb_setdone); holder.repscapt = (edittext) view.findviewbyid(r.id.et_reps_number); holder.repscapt.settag(position); holder.repscapt.settext(texts.get(position)); //holder.weightcapt = (edittext) view.findviewbyid(r.id.et_weight_number); //db = new databasehandler(this.getcontext()); //holder.weightcapt.settag(position); view.settag(holder); } else { holder = (holder) convertview.gettag(); } exerciseset exercise = mexercise.get(position); /* * edit texts */ int tag_position=(integer) holder.repscapt.gettag(); holder.repscapt.setid(tag_position); holder.repscapt.addtextchangedlistener(new textwatcher() { @override public void ontextchanged(charsequence s, int start, int before, int count) { final edittext repstext = (edittext) holder.repscapt; if(repstext.gettext().tostring().length()>0){ texts.add(repstext.gettext().tostring()); }else{ toast.maketext(getcontext(), "please come in value", toast.length_short).show(); } } @override public void beforetextchanged(charsequence s, int start, int count, int after) { // todo auto-generated method stub } @override public void aftertextchanged(editable s) { } }); if (exercise != null) { holder.setcounterview.settext(string.valueof(exercise.getsetid())); } /* * check boxes */ holder.cbset.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton button, boolean ischecked) { if(ischecked) mexercise.get(position).setcbchecked(true); else mexercise.get(position).setcbchecked(false); } }); holder.cbset.setchecked(exercise.iscbchecked()); } homecoming view; } static class holder { public edittext weightcapt; public edittext repscapt; // header row items textview exercisetitleview; // body row item checkbox cbset; textview setcounterview; } }

i dont know why, please help..

edit_1: tried saving values arraylist , retrieve them while views reused still gives me duplicated values while scroll down.

edit_2: if question unclear please allow me know!

edit_3: placed holder.repscapt.settext(texts.get(position)) within if (exercise != null) { status , values not duplicated anymore. still if scroll downwards , values messed up.

your problem certainly connected item views beingness reused list. check conditions , create sure provide alternative text in cases. let's begin item type==0 this:

if (exercise != null) holder.exercisetitleview.settext(exercise.getexercisetitle());

add

else holder.exercisetitleview.settext("debugging: nil show");

edit same type==1: - holder.repscapt.settext(texts.get(position)) called on freshly inflated view - holder.setcounterview.settext(string.valueof(exercise.getsetid())) when excersise not null

edit2 well, debug purposes seek not reuse views in getview() - always inflate right start.

if becomes ok (or empty fields) homecoming initial recommendation in post. suspect scenario

if problem persists should pay attending correctly getting info according position.

android listview android-edittext

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -