use of com.google.firebase.quickstart.database.models.Comment in project quickstart-android by firebase.
the class PostDetailActivity method postComment.
private void postComment() {
final String uid = getUid();
FirebaseDatabase.getInstance().getReference().child("users").child(uid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get user information
User user = dataSnapshot.getValue(User.class);
String authorName = user.username;
// Create new comment object
String commentText = mCommentField.getText().toString();
Comment comment = new Comment(uid, authorName, commentText);
// Push the comment, it will appear in the list
mCommentsReference.push().setValue(comment);
// Clear the field
mCommentField.setText(null);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Aggregations