How to add object at the beginning of the list in ArrayAdapter?

krinn picture krinn · Oct 21, 2012 · Viewed 10.6k times · Source

ArrayAdapter has method add(T object) which add an object at the end of a list. Is there a way to add object at the beginning of the list?

Answer

Eric picture Eric · Oct 21, 2012

You can use the .insert(T object, int index) method for this, using 0 as an index:

yourAdapter.insert(object, 0);