android - Random tick/check while checking my checkbox in Custom Listview -
while checking checkbox in custom listview or scroll or down checking has been done checkbox have not clicked or touched. here i'm attaching getview
method,
@override public view getview(int position, view convertview, viewgroup parent) { if (translist != null) { final int pos = position; if (convertview == null) { convertview = inflater.inflate(r.layout.export_item_list, null); checkbox = (checkbox) convertview.findviewbyid(r.id.export_chk); txtordno = (textview) convertview.findviewbyid(r.id.txt_exportordno); txtorddate = (textview) convertview.findviewbyid(r.id.txt_exportdate); txtordstatus = (textview) convertview.findviewbyid(r.id.txt_exportstatus); convertview.settag(new ordersviewholder(checkbox, txtordno, txtorddate, txtordstatus)); // checkbox click function checkbox.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { checkbox cb = (checkbox) v; if (cb.ischecked()) { cb.setchecked(true); // save item in preference string itemname = translist.get(pos).gethhtran_referencenumber(); supporter.saveorderinpreference(itemname, 1); //to check , uncheck selectall checkbox if(!selectall.ischecked()) { boolean selectcheck = true; int c=exportitems.getchildcount(); for(int i=0; i<exportitems.getchildcount();i++) { linearlayout listviewlayout = (linearlayout) exportitems.getchildat(i); checkbox chkbox = (checkbox) listviewlayout.findviewbyid(r.id.export_chk); system.out.println("i="+i); if(!chkbox.ischecked()) { selectcheck = false; system.out.println("i inside="+i); break; } } if(selectcheck){ selectall.setchecked(true); supporter.setselectallcheckedfororder(); } } } else { cb.setchecked(false); supporter.removeorderfrompreference(translist.get(pos).gethhtran_referencenumber()); //to check , uncheck selectall checkbox if(selectall.ischecked()) { selectall.setchecked(false); supporter.setselectallnotcheckedfororder(); } } } }); boolean isexist = isorderexist(translist.get(pos).gethhtran_referencenumber()); if (isexist) { // set qty // int qty = // getmyitem(reciptlist.get(pos).gethhreceipt_docnumber()); checkbox.setchecked(true); } else { checkbox.setchecked(false); } } else { ordersviewholder viewholder = (ordersviewholder) convertview .gettag(); checkbox = viewholder.getcheckbox(); txtordno = viewholder.gettxtordno(); txtorddate = viewholder.gettxtorddate(); txtordstatus = viewholder.gettxtordstatus(); } int day = translist.get(position).gethhtran_transday(); int month = translist.get(position).gethhtran_transmonth(); int year = translist.get(position).gethhtran_transyear(); string strdate = supporter.getstringdate(year, month, day); int stusval = translist.get(position).gethhtran_status(); system.out.println("order status:"+stusval); string strstaus = ""; if (stusval == 0) { strstaus = "new"; } else { strstaus = "exported"; } txtordno.settext(translist.get(position).gethhtran_referencenumber()); txtorddate.settext(strdate); txtordstatus.settext(strstaus); } return convertview; }
please me out resolve it.
you're setting checked
status in convertview == null
branch. you're not setting in else
branch, checked status of recycled checkbox retained.
just move code sets checkbox checked status out of if
-else
set both new , recycled views.
Comments
Post a Comment