Jason Wood
Jason Wood

Reputation: 729

add items on top of the listview android

I have a listview and I am using list.add(mylist) and adapter.notifydatasetchanged() ,its adding the items below the existing list ,How Do I add the Items on Top of the List.

Eg: If I receive new msgs It should be on top of the existing list.

Thanks in Advance.

Upvotes: 3

Views: 8358

Answers (2)

katogeaver
katogeaver

Reputation: 79

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

list.setAdapter(adapter);

...

adapter.insert(data, 0);

It shoudl update by itself because you had it bound

Upvotes: 4

techi.services
techi.services

Reputation: 8533

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

Upvotes: 14

Related Questions