![]() |
VOOZH | about |
This is the Part 15 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 AdapterChat.java file
We can delete a message only if we are the sender of the message. There are two methods to delete the message. You can use any one of them. In one, we have removed the value using datasnapshot and in another, we have updated the message as "This Message Was Deleted" as we see in WhatsApp.
if(dataSnapshot1.child("sender").getValue().equals(myuid)) {
// any two of below can be used
dataSnapshot1.getRef().removeValue();
// <----------------------------------->
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("message", "This Message Was Deleted");
dataSnapshot1.getRef().updateChildren(hashMap);
Toast.makeText(context,"Message Deleted.....",Toast.LENGTH_LONG).show();
}
Below is the code for the AdapterChat.java file.
Output:
Note: Please Add drawable items before running the Application
Below is the file structure after performing these operations:
👁 Image