Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To maintain the three Android fragments in ViewPager active, you need to follow these steps:

  1. Initialize your Viewpager with FragmentPagerAdapter or FragmentStatePagerAdapter.

  2. Override the getCount() method and return the number of fragments you want to display. In your case, it will be three.

  3. Implement the getItem() method and create a new instance of the appropriate fragment according to the position.

  4. Make sure you do not destroy any fragment when it goes out of the screen. To do that, you can override the destroyItem() method and remove the call to the super method.

  5. Ensure that you call mViewPager.setOffscreenPageLimit(2); to retain the three fragments in memory and avoid recreating them on scroll.

With these steps, you should be able to maintain the three Android fragments in ViewPager active.