I'm currently working on a music app which has a "Favorite Songs" tab. I'm trying to implement a tool that will allow the users to sort their favorite songs which are stored in a DATABASE using drag & drop.
I'm using ItemTouchHelper
for that case, But none of my searches produced a solution that works with a database.
** My list gets populated from the database **
FavoritesPresenter.class
ItemTouchHelper.SimpleCallback simpleCallback =
new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
mRecyclerView.notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
return true;
}
@Override
public void onMoved(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, int fromPos, RecyclerView.ViewHolder target, int toPos, int x, int y) {
super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y);
}
DataBase.class
int updateOrder(long id, int newPos) {
ContentValues cv = new ContentValues();
cv.put(DataBaseOpenHelper.COLUMN_ORDER, newPos);
String where = DataBaseOpenHelper.COLUMN_ID + "=?";
String[] whereArgs = {String.valueOf(id)};
return getWritable().update(DataBaseOpenHelper.TABLE_NAME_FAVORITE, cv, where, whereArgs);
}
I've tried this "solution" here, But obviously it's not working for me. Any suggestions ?