Q:

Swap two elements in ArrayList inside custom adapter to show in Listview

I have a Listview and a custom adapter, I am trying to change swap two arraylist items inside the apdapter in onclick of button as listview item.
My code is
viewHolder.btnUp.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Integer pos = (Integer) v.getTag();

            if (!pojos.get(pos).equals(pojos.get(0))) {

                Collections.swap(pojos, pos, pos - 1);

                notifyDataSetChanged();
            }
        }
    });

But I can not see the changes in listview, though arraylist has modified, but UI changes has not reflected.

A:

Thats because your adapter has already finished its work. The adapter will turn the data into views and pass those views to the list view. Notice that changing the order in the original collection wont change the views inside the list view. What you could do is remove the views and add them at the correct positions. Get access to the list view by doing viewHolder.getParent()

