listview - Android lost of check state after scrolling -
whenever scrolling , down, lose check state of checkbox.
i can't solve problem 2 days......
please me
here code.
public view getview(final int position, view view, viewgroup parent) { context = parent.getcontext(); inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); if (view == null) { holder = new viewholder(); view = inflater.inflate(r.layout.custom_llistview, parent, false); holder.img_view = (imageview) view.findviewbyid(r.id.custom_imageview); holder.txt_view = (textview) view.findviewbyid(r.id.custom_textview); holder.checkbox = (checkbox) view.findviewbyid(r.id.check_box); view.settag(holder); } else { holder = (viewholder)view.gettag(); } holder.checkbox.setchecked(check_flag_arr[position]); holder.checkbox.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked) { check_flag_arr[position] = ischecked; else { check_flag_arr[position] = ischecked; } } }); file_path = list_item.get(position).getfile_path(); bitmap showimage = bitmapfactory.decodefile(file_path); holder.img_view.setimagebitmap(showimage); list_contents = file_path.substring(45, 65); holder.txt_view.settext(list_contents); return view; }
and detail explanation great pleasure me.
i must solve problem.
thanks watching post.
when scroll, setoncheckedchangelistener called. handle in view need below -
holder.checkbox.setoncheckedchangelistener(null); holder.checkbox.setchecked(_songs.get(position).isselected());
you first need set onchecked null on scroll when view getting populated , assigning views, don't call oncheckedlistener.
and need call oncheckedchangelistener
holder.checkbox.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (holder.checkbox.ischecked()) { check_flag_arr[position] = true; } else { check_flag_arr[position] = false; } } });
Comments
Post a Comment