Nevaeh
Nevaeh

Reputation: 1569

How to swap two items in Android ListView?

I have a listview in which i have 5 integer items.How to change the positions of items in the listview.Suppose i want to swap first and third items in the listview.How can this be achieved ?Somebody please help...

Upvotes: 0

Views: 2911

Answers (1)

Faruk Yazici
Faruk Yazici

Reputation: 2404

1.Perform the swap in the List that constitutes your ListView,

int temp = list.get(2);
list.set(2,list.get(0));
list.set(0,temp);

2.Notify your adapter about this change;

adapter.notifyDataSetChanged();

Upvotes: 1

Related Questions