I\'m new to android and I\'ve been playing around with this sample app from firebase. I want to add a delete button on PostDetailActivity which deletes the current post being vi
You just need to add an if
statement to check if the dataSnapshot
has a value or null
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
// Get Post object and use the values to update the UI
Post post = dataSnapshot.getValue(Post.class);
// Text Views in activity
mAuthorView.setText(post.author);
mTitleView.setText(post.title);
mBodyView.setText(post.body);
}
}