【发布时间】:2020-06-05 19:33:17
【问题描述】:
我实现了一个操作模式工具栏,允许我删除我的 recyclerView 中的多个项目。我有一个所有选定项目索引的整数列表。所以我想知道执行我的请求的更好方法是什么。
目前,当我尝试删除 3 个项目时,出现错误:java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionNoteListViewHolder
这是我的代码:
private void deleteNote() {
List<Note> temp = new ArrayList<>(notes);
List<Integer> selectedItems = noteListAdapter.getSelectedItems();
notes.removeAll(selectedItems.stream().map(notes::get).collect(Collectors.toList()));
for (int notes_index: selectedItems) {
noteListAdapter.notifyItemRemoved(notes_index);
}
Snackbar snackbar = Snackbar.make("test").setAction("ANNULER", v1 -> {
// reinsert the note if undo action
for (int index: selectedItems) {
notes.add(index, temp.get(index));
noteListAdapter.notifyItemInserted(index);
}
});
snackbar.show();
}
【问题讨论】:
标签: java android android-studio android-recyclerview android-actionmode