Hi I have an array adapter that is populated from an array like 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 is that objects with type equal to place are still output as rows.
In addition I try to remove the objects from the array above the IF like 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 I do this, I get a concurrent editing exception.
How I simply limit rows of a certain type from being displayed?
Thanks!
Answering your second question, you’re not allowed to modify a list directly while an iterator is traversing it, as doing so could theoretically cause the iterator to fail in a number of ways (skip elements, get stuck in an infinite loop). There is, however, a remove() method on Iterator that will remove the last item returned from next(), which should do what you want here:
Another way of approaching your problem might be to define a Cursor that traverses your list, only stopping at the items you want, and then using a CursorAdapter rather than ArrayAdapter. It’s a bit more work, but has the advantage that it doesn’t require any up-front processing, so might be a bit more responsive.