Add items on top of Android list

I have a listview, and I use list.add (mylist) and adapter.notifydatasetchanged (), adding items below the existing list. How to add items at the top of the list.

For example: if I receive new messages, it should be on top of the existing list.

Thanks at Advance.

+3
source share
2 answers

Use add(int index, E object). Where index = 0.

+14
source

Actually, if you bind your adapter to the ListView list, you can also just insert an element into your adapter with the position (in this case, 0)

list.setAdapter(adapter);

...

adapter.insert(data, 0);

This shoudl update is in itself because you linked it

+4
source

All Articles