I am storing user post data in firebase realtime database and displaying those post in a list view. I have set the list view on button click listener so that user can delete it if he/she wants. I have used push(), so random key is generating when user making new post. Now i am not being able to delete it. I have also tried to put that key as child also, but i am not finding any way how to delete it. Any help is much appreciated.
I want this "-LX5Db4_suS_wPjzRDLE" to be deleted only when user will click this post from the list view. As i am using this to display in user post history so i can only get the 1st child using getUid() for current user.
Here is the code i have tried,
FirebaseDatabase database=FirebaseDatabase.getInstance();
final DatabaseReference ref=database.getReference("Donation Post").child(user.getUid());
ref.removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Toast.makeText(UserPostHistoryActivity.this, "Post Deleted Successfully", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(UserPostHistoryActivity.this, "Post Not Deleted!!!", Toast.LENGTH_SHORT).show();
}
}
});