I have an arraylist which is displayed in a listview. The items in this listview can be rearranged. The items are displayed in random order using Collections.shuffle. I want to rearrange the items inside the listview according to its designated procedure number.
For example:
Procedure number 4 //index 0
Procedure number 2 //index 1
Procedure number 1 //index 2
Procedure number 3 //index 3
Once the user dragged "Procedure number 3" and dropped it at index 0, this should display a toast that it is placed in the wrong position. But if it is dropped at index 2, this should display a toast that it is in the correct position of index.
Here's a snippet of my code:
How can I achieve this? Any help is appreciated. Thank you.
For example:
Procedure number 4 //index 0
Procedure number 2 //index 1
Procedure number 1 //index 2
Procedure number 3 //index 3
Once the user dragged "Procedure number 3" and dropped it at index 0, this should display a toast that it is placed in the wrong position. But if it is dropped at index 2, this should display a toast that it is in the correct position of index.
Here's a snippet of my code:
Java:
mItemArray = new ArrayList<>();
for (int i = 0; i < 8; i++) {
mItemArray.add(new Pair<>(Long.valueOf(i), "Procedure number " + i));
}
Collections.shuffle(mItemArray);
mDragListView.setDragListListener(new DragListView.DragListListenerAdapter() {
@Override
public void onItemDragStarted(int position) {
mRefreshLayout.setEnabled(false);
Toast.makeText(mDragListView.getContext(), "Start - position: " + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onItemDragEnded(int fromPosition, int toPosition) {
mRefreshLayout.setEnabled(true);
if (fromPosition != toPosition) {
Toast.makeText(mDragListView.getContext(), "End - position: " + toPosition, Toast.LENGTH_SHORT).show();
}
}
});
How can I achieve this? Any help is appreciated. Thank you.