I have a two dimensional ArrayList
of type String
which is the input to the adapter class of the RecyclerView
. The data in the list is
You need a field in each DB row for storing the order. Then you need to implements those features:
On new row insert (when you insert a new object in database) you need to set the order field to the next int. You can get the current max value (with sql function MAX
) and then simply do +1
When user move an item in RecyclerView
, in method onMoved
you must update all other rows. You can use the fromPos
and toPos
for that. More on that below
When you fill your RecyclerView
with data you need to order them by order
field
Explanation of 2nd feature to be implemented:
basically you need to update all rows with order between fromPos
and toPos
:
if user moved the item up (for example from position 4 to 2), you need to:
toPos
: in this example change current item order to 2if user moved the item down (for example from position 2 to 4) you need to:
toPos
: in this example change current item order to 4
Hope it helps a little