0

For some reason my recyclerView doesn't attach to the Firebase RecyclerView adapter. I'm implementing the recyclerView inside a fragment that shows in a tabbed activity. my code (relevant parts):

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = LayoutInflater.from(container.getContext())
                            .inflate(R.layout.fragment_fresh, container, false);

        // Initialize ProgressBar and RecyclerView.
        mProgressBar = (ProgressBar)rootView.findViewById(R.id.progressBar);
        mSessionRecyclerView = (RecyclerView) rootView.findViewById(R.id.sessionRecyclerView);
        mLinearLayoutManager = new LinearLayoutManager(getActivity());
        mLinearLayoutManager.setStackFromEnd(true);
        mSessionRecyclerView.setLayoutManager(mLinearLayoutManager);

        //implement recyclerview
        mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
        mFirebaseAdapter = new FirebaseRecyclerAdapter<Session, SessionViewHolder>(
                Session.class,
                R.layout.item_session,
                SessionViewHolder.class,
                //change back to SESSIONS_CHILD
                mFirebaseDatabaseReference.child("test")) {
            @Override
            protected void populateViewHolder(final SessionViewHolder viewHolder,
                                              Session session, int position) {

              //implementing populateViewHolder..
            }
        };



        mSessionRecyclerView.setLayoutManager(mLinearLayoutManager);
        mSessionRecyclerView.setAdapter(mFirebaseAdapter);

        return inflater.inflate(R.layout.fragment_fresh, container, false);
    }

}

The XML is just a recyclerView and a progressBar. Worth mentioning that I've gone through this thread.Tried setting recycler's size to wrap_parent, move setAdapter to onCreate, and pretty much every other answer - to no avail.

EDIT: I got this working when inside an activity, but whenever I try from within a fragments I get this error. Also tried with a regular recyclerView and a custom adapter and the same thing happens. Does the recyclerView attaches itself to an adapter differently in a fragment?

Community
  • 1
  • 1
Barazu
  • 489
  • 6
  • 10

1 Answers1

0

OK, I finally fixed it. The problem was actually in the tabbed activity - the getItem method inside the PlaceHolder fragment created a new instance of PlaceHolder. Therefore, my fragments hadn't even been created. None of the threads on the skipping layout advise checking that, hope this helps.

Barazu
  • 489
  • 6
  • 10