android - ListView has "blank" rows -
my listview size isn't updating according adapter, , i'm not sure why (this happening after filter based on category, i'll post category filter well) can see after looking @ images there blank rows in filtered tab. image of "all" tab:
here getview method:
public view getview(int position,view view,viewgroup parent) { layoutinflater inflater = ctx.getlayoutinflater(); view rowview = inflater.inflate(r.layout.list_item, null, true); try { item = getforname(names.get(position)); if (i.iscategory()) { rowview = inflater.inflate(r.layout.cat_item, null, true); textview text = (textview) rowview.findviewbyid(r.id.cattxt); text.settext(i.gettitle()); text.settypeface(null, typeface.bold); } else { textview text = (textview) rowview.findviewbyid(r.id.listtext); imageview image = (imageview) rowview.findviewbyid(r.id.listimage); try { text.settext(names.get(position)); image.setimageresource(imageids.get(position)); } catch (exception e) { } } } catch(exception ) { a.printstacktrace(); } return rowview; };
and here category filter method:
public void filtercategories(context context) { arraylist<string> currnames = new arraylist<>(); //list of names in current category (when start looping) arraylist<integer> currimaages = new arraylist<>(); //list of drawable ids in current category (when start looping) arraylist<string> n = new arraylist<>(); //will finalized names list arraylist<integer > = new arraylist<>(); //will finalized id list for(string name : names) { item item = getforname(name); if(item != null) if(item.iscategory()) { string cat = item.getacronym(); for(string n1 : names) { item i1 = getforname(n1); if(i1 != null && !i1.iscategory() && i1.getparent() != null && !currnames.contains(i1.gettitle())) { if(i1.getparent().equals(cat)) { currnames.add(n1); currimaages.add(context.getresources().getidentifier(getforname(n1).getthumbnail(), "drawable", context.getpackagename())); } } } n.add(name); is.add(0); int c = 0; for(string x : currnames) { n.add(x); is.add(currimaages.get(c)); c++; } } currnames = new arraylist<>(); currimaages = new arraylist<>(); } names = new arraylist<>(); imageids = new arraylist<>(); for(string : n) { names.add(a); } for(integer : is) { imageids.add(a); } notifydatasetchanged(); }
here's output a.printstacktrace():
06-04 09:51:38.835 17900-17900/packagename w/system.err﹕ java.lang.indexoutofboundsexception: invalid index 9, size 7 06-04 09:51:38.835 17900-17900/packagename w/system.err﹕ @ java.util.arraylist.throwindexoutofboundsexception(arraylist.java:255) 06-04 09:51:38.835 17900-17900/packagename w/system.err﹕ @ java.util.arraylist.get(arraylist.java:308) 06-04 09:51:38.835 17900-17900/packagename w/system.err﹕ @ packagename.util.listadapter.getview(listadapter.java:46) 06-04 09:51:38.835 17900-17900/packagename w/system.err﹕ @ android.widget.abslistview.obtainview(abslistview.java:2387) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.listview.makeandaddview(listview.java:1864) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.listview.filldown(listview.java:698) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.listview.fillspecific(listview.java:1356) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.listview.layoutchildren(listview.java:1651) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.abslistview.onlayout(abslistview.java:2191) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.linearlayout.setchildframe(linearlayout.java:1705) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.linearlayout.layoutvertical(linearlayout.java:1559) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.linearlayout.onlayout(linearlayout.java:1468) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.support.v4.widget.drawerlayout.onlayout(drawerlayout.java:907) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.framelayout.layoutchildren(framelayout.java:573) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.framelayout.onlayout(framelayout.java:508) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.support.v7.internal.widget.actionbaroverlaylayout.onlayout(actionbaroverlaylayout.java:493) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.framelayout.layoutchildren(framelayout.java:573) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.framelayout.onlayout(framelayout.java:508) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.linearlayout.setchildframe(linearlayout.java:1705) 06-04 09:51:38.836 17900-17900/packagename w/system.err﹕ @ android.widget.linearlayout.layoutvertical(linearlayout.java:1559) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.widget.linearlayout.onlayout(linearlayout.java:1468) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.widget.framelayout.layoutchildren(framelayout.java:573) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.widget.framelayout.onlayout(framelayout.java:508) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.view.layout(view.java:15654) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.viewgroup.layout(viewgroup.java:4967) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2102) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1859) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1078) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5875) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.choreographer$callbackrecord.run(choreographer.java:767) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.choreographer.docallbacks(choreographer.java:580) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.choreographer.doframe(choreographer.java:550) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.os.handler.handlecallback(handler.java:739) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.os.handler.dispatchmessage(handler.java:95) 06-04 09:51:38.837 17900-17900/packagename w/system.err﹕ @ android.os.looper.loop(looper.java:135) 06-04 09:51:38.841 17900-17900/packagename w/system.err﹕ @ android.app.activitythread.main(activitythread.java:5299) 06-04 09:51:38.841 17900-17900/packagename w/system.err﹕ @ java.lang.reflect.method.invoke(native method) 06-04 09:51:38.841 17900-17900/packagename w/system.err﹕ @ java.lang.reflect.method.invoke(method.java:372) 06-04 09:51:38.841 17900-17900/packagename w/system.err﹕ @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:908) 06-04 09:51:38.841 17900-17900/packagename w/system.err﹕ @ com.android.internal.os.zygoteinit.main(zygoteinit.java:703)
the issue handling getview method wrong. here going add sample code.
step 1 need viewholder class this. add inflated xml widgets here:
/********* create holder class contain inflated xml file elements *********/ public static class viewholder{ public textview text; public textview text1; public textview textwide; public imageview image; }
step 2
in getview method
/****** depends upon data size called each row , create each listview row *****/ public view getview(int position, view convertview, viewgroup parent) { view vi = convertview; viewholder holder; if(convertview==null){ /****** inflate tabitem.xml file each row ( defined below ) *******/ vi = inflater.inflate(r.layout.tabitem, null); /****** view holder object contain tabitem.xml file elements ******/ holder = new viewholder(); holder.text = (textview) vi.findviewbyid(r.id.text); holder.text1=(textview)vi.findviewbyid(r.id.text1); holder.image=(imageview)vi.findviewbyid(r.id.image); /************ set holder layoutinflater ************/ vi.settag( holder ); } else holder=(viewholder)vi.gettag(); return vi; }
this sample ask doubts
Comments
Post a Comment