Monday, 15 February 2010

listview - How to stop list recycling On Scroll of list View, in a custom cursor adapter android -



listview - How to stop list recycling On Scroll of list View, in a custom cursor adapter android -

i creating 1 list divided categories passing view in list view (using simple cursor adapter) using view holder. in custom simple cursor adapter can set visibility of 1 single bar on each items of list. but on scroll visibility of bar not fixed list items, gets changed randomly , down. check code posting here.

when phone call custom cursor list adapter's constructor normal activity passing parameters(the view, cursor) , , i on riding bind view not newview.

please help me on this.

activity is:

catcount = cursorcat.getcount(); int i=0; cursorcat.movetofirst(); { categ = cursorcat.getstring(cursorcat.getcolumnindex("category_name")); cursorcatitems = db.rawquery("select _id, product_code, product_name, product_category, in_stock, cost productdetails _id || ' ' || product_name || product_code ? ", new string[] { "%" +searchvalue+ "%"}); adapter = new mforceadaptercat(this, r.layout.item_details, cursorcatitems, new string[] { "product_code", "product_name","product_category","in_stock","price" }, new int[] { r.id.tvcode, r.id.tvitemname,r.id.tvitemtype,r.id.tvquantity,r.id.tvprice }); listview.setadapter(adapter); i++; } while (cursorcat.movetonext() && i<catcount-1); cursorcat.close(); // downwards here code list view items @suppresslint("newapi") public class mforceadaptercat extends simplecursoradapter { string prevcat=""; int count=0; private final string tag = this.getclass().getsimplename(); protected listadapter adapter; public mforceadaptercat(context context, int layout, cursor c, string[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); // todo auto-generated constructor stub } @suppresswarnings("deprecation") public mforceadaptercat(context context, int layout, cursor c, string[] from, int[] to) { super(context, layout, c, from, to); // todo auto-generated constructor stub } @override public int getitemviewtype(int position) { // todo auto-generated method stub homecoming super.getitemviewtype(position); } @override public void bindview(view view, context context, cursor cursor) { super.bindview(view, context, cursor); viewholder holder = (viewholder) view.gettag(); holder = new viewholder(); holder.tvcode = (textview) view.findviewbyid(r.id.tvcode); holder.tvitemname = (textview) view.findviewbyid(r.id.tvitemname); holder.tvitemtype = (textview) view.findviewbyid(r.id.tvitemtype); holder.tvprice = (textview) view.findviewbyid(r.id.tvprice); holder.tvquantity = (textview) view.findviewbyid(r.id.tvquantity); holder.imgbtnlv=(imagebutton) view.findviewbyid(r.id.imgbtnlv); holder.categbar=(linearlayout) view.findviewbyid(r.id.categbar); holder.tvtitlecateg=(textview) view.findviewbyid(r.id.tvtitlecateg); holder.item_detail_layout=(relativelayout) view.findviewbyid(r.id.item_detail_layout); string currcategory = cursor.getstring(cursor.getcolumnindex("product_category")); holder.tvtitlecateg.settext(currcategory); if(prevcat.equalsignorecase(currcategory)){ holder.categbar.setvisibility(view.gone); }else{ holder.categbar.setvisibility(view.visible); } prevcat= currcategory; onclicklistener monimagebtnclicklistener = new onclicklistener() { @override public void onclick(view v) { final int position = productsactivity.listview.getpositionforview((view) v.getparent()); log.v(tag, "image button in list clicked, row ="+position); listadapter la= productsactivity.listview.getadapter(); system.out.println("list adapter ="+la); int cnt = getpositionfromrowid(la, position, 0, la.getcount()); system.out.println("info new mthod ="+cnt); } }; holder.imgbtnlv.setonclicklistener(monimagebtnclicklistener); view.settag(holder); } static class viewholder { textview tvcode; textview tvitemname,tvitemtype,tvprice,tvquantity; relativelayout item_detail_layout; imagebutton imgbtnlv; linearlayout categbar; textview tvtitlecateg; }

the way using viewholder makes no sense. it's useless imho. see here: http://www.jmanzano.es/blog/?p=166

you not inflating views here don't need it. viewholder should used remove redundant view inflating , reuse view, in cursor adapter reusing view done. can delete it.

android listview scroll

No comments:

Post a Comment