I received the user's email and designated it as the name of the document,
and stored the user information in the document in an array. I tried running my code, but only the Toast message is executed, not deleted.
I have listed the arrays as a list using RecyclerView
. Deletion will be implemented through showPop()
method.
This is my Firestore database enter image description here
I want to delete index-0
private void showPopup(View v,final int position) {
PopupMenu popup = new PopupMenu(activity, v);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
.....
case R.id.delete: //delete
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
final FirebaseFirestore db = FirebaseFirestore.getInstance();
final Map<String, Object> updates = new HashMap<>();
updates.put(user.getEmail(),FieldValue.delete());
//db.collection("medicinday").document(mDataset.get(position).getId())
// .delete()
db.collection("medicinday").document(user.getEmail()).update("add_day", FieldValue.arrayRemove(user.getEmail()))
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(....
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
....
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…