How to not show a record in an array adapter based on IF criteria in android -
hi have array adapter populated array so:
private class placesdetailadapter extends arrayadapter<placedetail> { private arraylist<placedetail> items; public placesdetailadapter(context context, int textviewresourceid, arraylist<placedetail> items) { super(context, textviewresourceid, items); this.items = items; } @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { layoutinflater vi = (layoutinflater)getsystemservice(context.layout_inflater_service); v = vi.inflate(r.layout.placedetail_list_row, null); } placedetail o = items.get(position); if (!o.gettype.equals("place") { textview tt = (textview) v.findviewbyid(r.id.placedetailtitle_txt); tt.settext(o.getname()); imageview iv = (imageview) v.findviewbyid(r.id.placedetailicon_img); iv.setimagebitmap(o.getimage); } return v; } }
the problem objects type equal place still output rows.
in addition try remove objects array above if so:
iterator iter = m_orders.iterator(); while(iter.hasnext()){ placedetail vs = (placedetail)iter.next(); if(vs.gettype().equals("place")) { m_orders.remove(vs); } }
m_adapter.notifydatasetchanged();
when this, concurrent editing exception.
how limit rows of type being displayed?
thanks!
answering second question, you're not allowed modify list directly while iterator traversing it, doing theoretically cause iterator fail in number of ways (skip elements, stuck in infinite loop). there is, however, remove() method on iterator remove last item returned next(), should want here:
iterator iter = m_orders.iterator(); while(iter.hasnext()){ placedetail vs = (placedetail)iter.next(); if(vs.gettype().equals("place")) { iter.remove(); } } m_adapter.notifydatasetchanged();
another way of approaching problem might define cursor traverses list, stopping @ items want, , using cursoradapter rather arrayadapter. it's bit more work, has advantage doesn't require up-front processing, might bit more responsive.
Comments
Post a Comment