Delete an item from firebase without crashing the app

后端 未结 1 871
温柔的废话
温柔的废话 2021-01-25 03:05

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

相关标签:
1条回答
  • 2021-01-25 03:50

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题