![]() |
VOOZH | about |
This is the Part 11 of "Build a Social Media App on Android Studio" tutorial, and we are going to cover the following functionalities in this article:
Step 1: Create a new layout resource file
Go to the app > res > layout > Right-click > New > Layout Resource File and name the file as row_comments. Below is the code for the row_comments.xml file.
Step 2: Create a new java class and name the class as ModelComment
Working with the ModelComment.java file. Created this activity to initialize the key so that we can retrieve the value of the key later. Below is the code for the ModelComment.java file.
Step 3: Create another new java class and name the class as AdapterComment
Working with the AdapterComment.java file. Below is the code for the AdapterComment.java file.
Step 4:Working with the PostDetailsActivity Activity
Working with the activity_postdetails.xml file.
Working with the PostDetailsActivity.java file
Post Comment Using this:
DatabaseReference datarf= FirebaseDatabase.getInstance().getReference("Posts").child(postId).child("Comments");
HashMap<String ,Object> hashMap=new HashMap<>();
hashMap.put("cId",timestamp);
hashMap.put("comment",commentss);
hashMap.put("ptime",timestamp);
hashMap.put("uid",myuid);
hashMap.put("uemail",myemail);
hashMap.put("udp",mydp);
hashMap.put("uname",myname);
datarf.child(timestamp).setValue(hashMap);
Showing Comment like this:
DatabaseReference reference= FirebaseDatabase.getInstance().getReference("Posts").child(postId).child("Comments");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
commentList.clear();
for (DataSnapshot dataSnapshot1:dataSnapshot.getChildren()){
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
Below is the code for the PostDetailsActivity.java file.
Output:
Note: Please Add drawable items before running the Application
Below is the file structure after performing these operations:
👁 Image