Skip to content

Relation list order #243

@Verteletsky

Description

@Verteletsky

And how can I actually update an existing list in the database, for example, the elements are interchanged? In the put method, I pass a list with the same elements, only the position in the list is changed, but still when the application is restarted, it issues the order that was originally.

###Code

@Override
    public void onItemMove(int oldPosition, int newPosition) {
//        Note targetNote = dataset.get(oldPosition);
//        Note note = new Note(targetNote);
//        dataset.remove(oldPosition);
//        dataset.add(newPosition, note);
//        notifyItemMoved(oldPosition, newPosition);

        if (oldPosition < newPosition) {
            for (int i = oldPosition; i < newPosition; i++) {
                Collections.swap(dataset, i, i + 1);
            }
        } else {
            for (int i = oldPosition; i > newPosition; i--) {
                Collections.swap(dataset, i, i - 1);
            }
        }

        notesBox.put(dataset);
//        dataset.clear();
//        dataset.addAll(noteQuery.find());
        notifyItemMoved(oldPosition, newPosition);
//        notifyDataSetChanged();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions