0

I have a simple code with a RecyclerView, CardView, and an adapter. And I retrieve the data from the Firestore.

Problem:

I have a publishing feed, for example. And in this feed I have a button that takes another screen.

In this second screen I use as a return method: Finish.

But the problem is that the feed is large and coming back from the second screen to the first screen, RecyclerView goes to the beginning.

Is there any way I can not start the RecyclerView on top when I return to the activity that contains the feed?

Sample Image:

1 - First screen where it is clicked to see users who enjoyed a post. (This screen is a fragment.)

enter image description here

2 - List screen of users who liked the post.

enter image description here

3 - The first screen, but after you return. This screen always returns to the top.

enter image description here

Thanks!!

EDIT:

Code adapter + recyclerview in Fragment:

/* Recycler */
        mCardFeedList = (RecyclerView) view.findViewById(id.cardFeedUser_list);
        mCardFeedList.setHasFixedSize(true);
        mCardFeedList.setItemViewCacheSize(20);
        mCardFeedList.setDrawingCacheEnabled(true);


        mAdapter = new PostsAdapter(mQueryNew, this){

            @Override
            protected void onDataChanged() {

                if (getItemCount() == 0) {
                    mCardFeedList.setVisibility(View.GONE);
                    //mTxtVazio.setVisibility(View.VISIBLE);

                } else {
                    mCardFeedList.setVisibility(View.VISIBLE);
                    //mTxtVazio.setVisibility(View.GONE);
                }


            }
        };

        mCardFeedList.setLayoutManager(new LinearLayoutManager(getActivity().getApplication()));
        mCardFeedList.setAdapter(mAdapter);
TiagoIB
  • 439
  • 7
  • 25

1 Answers1

0

To solve this, you need to override the following method from RecyclerView.Adapter:

onBindVIewHolder(viewholder, position)

Called by RecyclerView to display the data at the specified position.

So you can use it to bind the data you have to this view and set the correct viewstate on the view.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193