The error you get is not calling clear() on the ArrayAdapter . You are using the List implementation (possibly the default), which does not implement the clear() method and therefore the parent class, "ie, the AbstractList implementation that throws an UnsupportedOperationException .
If you pass the array to the constructor
public ArrayAdapter(Context context, int resource, T[] objects) { init(context, resource, 0, Arrays.asList(objects)); }
it calls Arrays.asList() , which returns a List , which you cannot add() to, remove() or clear() .
Use this constructor
public ArrayAdapter(Context context, int resource, List<T> objects) { init(context, resource, 0, objects); }
passing a LinkedList or an ArrayList containing your objects.
source share