I need some help to undo deleted child, I already have the snackbar showing the undo onclick but I am not sure how to recover the child, I have it saved in ExpenseBackUp, but how do I get it back? any idea?
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Expenses").child(FirebaseAuth.getInstance().getCurrentUser().getUid());
reference.child(postId).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
Expense expenseBackUp = new Expense(item, category, date, postId, amount);
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Snackbar.make(rv, item " has been deleted", Snackbar.LENGTH_LONG).setAction("UNDO", new View.OnClickListener() {
@Override
public void onClick(View view) {
//undo onClick actions
Toast.makeText(ExpensesActivity.this, item " recovered", Toast.LENGTH_SHORT).show();
}
}).show();
} else {
Toast.makeText(ExpensesActivity.this, "Something went wrong, try again" task.getException(), Toast.LENGTH_SHORT).show();
}
CodePudding user response:
Are you looking for:
reference.child(postId).setValue(expenseBackUp)