There is a RecyclerView with the ability to move items. Data items are stored in the database. How to save data about the sequence of elements in order to sort the list after getting from the database in order to transfer it to RecyclerView?

  • What makes you difficult? Saving to DB? Determining the sequence? Or what? - JVic
  • The database contains stored objects. From the database I retrieve them and get the List in a certain sequence (in order of id in the database). But in RecyclerView there should be its own sequence, the one defined by the user dragging the elements. How to implement it? - Dmitry Vedmed
  • Add another field to the database, did not you think? - JVic

1 answer 1

In the database, you make a separate field that will store the sort order. When moving items, save the current position to this field. When selecting, sort the cursor by this field.