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
The tutorial that you are following is wrong. To solve your problem, please consider following these steps.
Move all the code from the onStart()
method inside onCreate()
method except these two lines of code:
super.onStart();
firebaseAuth.addAuthStateListener(authStateListener);
Make your firebaseRecyclerAdapter
varaible global:
private FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter;
Remove FirebaseRecyclerAdapter<Blog, BlogViewHolder>
from the onCreate()
method.
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();
}
}
The most important thing is to remove the static
keyword from your class declaration. Should be only:
public class PostViewHolder extends RecyclerView.ViewHolder {}