I cant see any FirebaseRecyclerAdapter items on my layout

前端 未结 1 1271
星月不相逢
星月不相逢 2020-11-28 16:19

Im trying to retrieve data from Firebase database to my layout and i cant see any items of FirebaseRecyclerAdapter in the layout, please help. i followed a tuto

相关标签:
1条回答
  • 2020-11-28 16:46

    The tutorial that you are following is wrong. To solve your problem, please consider following these steps.

    1. Move all the code from the onStart() method inside onCreate() method except these two lines of code:

      super.onStart();
      firebaseAuth.addAuthStateListener(authStateListener);
      
    2. Make your firebaseRecyclerAdapter varaible global:

      private FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter;
      
    3. Remove FirebaseRecyclerAdapter<Blog, BlogViewHolder> from the onCreate() method.

    4. Add the following lines of code in the onStart() and onStop() methods.

      @Override
      protected void onStart() {
          super.onStart();
          firebaseRecyclerAdapter.startListening();
      }
      
      @Override
      protected void onStop() {
          super.onStop();
          if(firebaseRecyclerAdapter != null) {
              firebaseRecyclerAdapter.stopListening();
          }
      }
      
    5. The most important thing is to remove the static keyword from your class declaration. Should be only:

      public class PostViewHolder extends RecyclerView.ViewHolder {}
      
    0 讨论(0)
提交回复
热议问题