recyclerview-animators icon indicating copy to clipboard operation
recyclerview-animators copied to clipboard

Scroll on Animation with Firebase

Open troy21688 opened this issue 8 years ago • 0 comments

I am using the RecyclerView animation library found here. I am also using the FirebaseRecyclerAdapter, documentation located here.

Essentially, I want to scroll to the top of the RecyclerView as items are added to Firebase. It is tricky since I am not actually initializing the adapter with an ArrayList(), or any list, for that matter. Firebase handles all of the data management through the FirebaseRecyclerAdapter.

Here is my basic onCreateView():

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final View v = inflater.inflate(R.layout.fragment_new, container, false);
    Log.v("TAG", "ON CREATE CALLED FROM NEW");

    mRecyclerview = (RecyclerView) v.findViewById(R.id.list);
    mRecyclerview.setItemAnimator(new FadeInUpAnimator());


    mLayoutManager = new LinearLayoutManager(getContext());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mLayoutManager.setReverseLayout(true);
    mLayoutManager.setStackFromEnd(true);

    mRecyclerview.setLayoutManager(mLayoutManager);

    return v;
}

And my adapter:

    @Override
public void onStart() {
    super.onStart();

    mFireAdapter = new FirebaseRecyclerAdapter<Poll, PollHolder>(Poll.class, R.layout.latest_item, PollHolder.class, mBaseRef.child("Polls")) {
        @Override
        protected void populateViewHolder(PollHolder viewHolder, Poll model, int position) {
            mRecyclerview.scrollToPosition(position);
            viewHolder.mPollQuestion.setText(model.getQuestion());
            Picasso.with(getActivity().getApplicationContext())
                    .load(model.getImage_URL())
                    .fit()
                    .into(viewHolder.mPollImage);
            Log.v("TAG", model.getQuestion());
            Log.v("TAG", model.getImage_URL());
        }
    };

    mRecyclerview.setAdapter(mFireAdapter);
}

How would I scroll to the top of the RecylcerView as items are added? Note that I am calling:

mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);

since I need to reverse the order of the data in Firebase.

troy21688 avatar Dec 20 '16 03:12 troy21688