不刷项目,我用这个方法删除:
public void deleteItem(int index) {
Toast.makeText(this, ""+ index, Toast.LENGTH_SHORT).show();
firebaseFirestore.collection("ToDoList").document(mAuth.getCurrentUser().getUid())
.collection("todo")
.document(toDoList.get(index).getId())
.delete()
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
loadToDoList();
Snackbar snackbar = Snackbar
.make(relativeLayout, R.string.deleteIsSuccess, Snackbar.LENGTH_LONG);
snackbar.show();
}
});
}
但是我想使用滑动来删除,并且我有 swipehelper 类来从适配器中关闭项目。当我加载活动时,RecyclerWiew 中会显示关闭项目
public class SwiperHelper extends ItemTouchHelper.SimpleCallback {
ListAdapter adapter;
MainActivity activity;
public SwiperHelper(int dragDirs, int swipeDirs) {
super(dragDirs, swipeDirs);
}
public SwiperHelper (ListAdapter adapter) {
super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) ;
this.adapter = adapter;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
adapter.dismiss(viewHolder.getAdapterPosition());
}}
我尝试在 onSwiped 方法中编写我的 deleteItem 方法,但我无法获取要删除的项目数据库 ID。