Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 991
krinn Avatar asked Oct 21 '12 17:10

krinn


People also ask

How do you populate a ListView?

To add rows to a ListView you need to add it to your layout and implement an IListAdapter with methods that the ListView calls to populate itself. Android includes built-in ListActivity and ArrayAdapter classes that you can use without defining any custom layout XML or code.

What is notifyDataSetChanged in ListView?

notifyDataSetChanged. Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.


1 Answers

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

yourAdapter.insert(object, 0); 
like image 86
Cat Avatar answered Nov 08 '22 13:11

Cat