如何解决拖放项目触摸助手后在房间数据库中保存位置
找不到解决方案如何在更改后将位置保存在房间中?
@Query("SELECT * FROM notes WHERE id == :id")
Note getNoteId(int id);
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertNote(Note note);
@Update
void update(Note note);
...
Mainviewmodel viewmodel = new viewmodelProvider(this).get(Mainviewmodel.class);
viewmodel.getNotes().observe(this,notes -> {
notesFromDB = new ArrayList<>(notes);
... 试了不行
private final itemtouchhelper.SimpleCallback simpleCallback =
new itemtouchhelper.SimpleCallback(itemtouchhelper.UP | itemtouchhelper.DOWN |
itemtouchhelper.RIGHT | itemtouchhelper.LEFT,itemtouchhelper.RIGHT | itemtouchhelper.LEFT) {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView,@NonNull RecyclerView.ViewHolder viewHolder,@NonNull RecyclerView.ViewHolder target) {
Note note = notesAdapter.getNoteAt(viewHolder.getAdapterPosition());
Collections.swap(notesFromDB,viewHolder.getAdapterPosition(),target.getAdapterPosition());
recyclerView.getAdapter().notifyItemmoved(viewHolder.getAdapterPosition(),target.getAdapterPosition());
App.getInstance().getNoteDao().update(note);
return true;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。