Prashant Gosai
Prashant Gosai

Reputation: 1227

ViewPager Fragment RecycleView Reset

I have 3 fragments in the ViewPager.

Every fragment has a RecyclerView and I was adding items using a dialog in it. However, when I go to the last fragment (i.e. NoteFragment), the first fragment's (i.e. PersonalFragment) RecyclerView gets empty (all items are removed). The same thing happens when I come back to the first fragment, the last fragment's RecyclerView resets (all items are removed).

Upvotes: 1

Views: 98

Answers (1)

Reaz Murshed
Reaz Murshed

Reputation: 24211

It is difficult to understand without seeing some of your code which is related. I think you might have implemented the onResume function incorrectly. Each time you go to the third fragment in your ViewPager, the first Fragment needs to be reinitialized and you need to take care of this in your onResume function.

However, another workaround for your problem is setting the off-screen page limit of the ViewPager like the following.

viewPager.setOffscreenPageLimit(2);

Hope that helps.

Upvotes: 1

Related Questions