DragSortRecycler
DragSortRecycler copied to clipboard
getItemId in sample code should not use position
The getItemId in the sample code should not return position. If items are added or removed it will break the RecyclerView.
Ah thanks for the info, can you explain this a bit more please? Under what circumstances will it break, you mean if you do a notifyItemRemoved for example? TBH I wasn't entirely sure what should be returned here. Thanks.
View the last comment here: https://code.google.com/p/android/issues/detail?id=77846
It should be the primary key from a database, and I guess you can get away with hashCode if your items are unique.
OK thanks for the link. So it appears if you (wrongly) return position in getItemId you must use the generic notifyDataSetChanged and not the other notify* functions, otherwise it may confuse the recycler. I will look into this limitation. Thank you.
Just need to keep track of the position. Once my local changes are done I'll create a patch.
moveInterface.onItemMoved(selectedDragPosition, (int) newPos);