![]() |
VOOZH | about |
This is the Part 13 of "Build a Social Media App on Android Studio" tutorial, and we are going to cover the following functionalities in this article:
Step 1: Working with the AdapterPosts.java file
We will get the node inside the "Posts" which we want to delete. We are directly deleting the snapshot reference value.
Query query= FirebaseDatabase.getInstance().getReference("Posts").orderByChild("ptime").equalTo(pid);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1:dataSnapshot.getChildren()){
dataSnapshot1.getRef().removeValue();//removing the value after getting reference
}
pd.dismiss();
Toast.makeText(context,"Deleted Successfully",Toast.LENGTH_LONG).show();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
Below is the updated code for the AdapterPosts.java file.
Output:
Note: Please Add drawable items before running the Application
Below is the file structure after performing these operations: