Search in sources :

Example 1 with Comment

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) {
        }
    });
}
Also used : Comment(com.google.firebase.quickstart.database.models.Comment) User(com.google.firebase.quickstart.database.models.User) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1 Comment (com.google.firebase.quickstart.database.models.Comment)1 User (com.google.firebase.quickstart.database.models.User)1