Questions tagged [fragmentstatepageradapter]

Implementation of PagerAdapter class from the Android compatibility package that uses a Fragment to manage each page. This class also handles saving and restoring of fragment's state.

This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.


From the documentation of the FragmentStatePagerAdapter class:

Implementation of PagerAdapter that uses a Fragment to manage each page. This class also handles saving and restoring of fragment's state.

This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.

When using FragmentPagerAdapter the host ViewPager must have a valid ID set.

Subclasses only need to implement getItem(int) and getCount() to have a working adapter.

Tag Usage:

397 questions
-1
votes
2 answers

Need guidance in making efficient swipe views

New to android and recently learned swipe views a bit. In my app, it has 17 chapters and in each chapter, there will be 30 pages containing some text data, a user can swipe through. I need to use FragmentStatePagerAdapter to save memory but I need…
-1
votes
1 answer

FragmentStatePagerAdapter : continue to show the current fragment after dataset is changed

I have a viewPager. Say underlying dataset is d0,d1,d2,d3,etc, and corresponding fragments are f0,f1,f2,f3... Currently Fragment f1 is visible i.e. position 1 of ViewPager. d0, is removed and notifyDataSetChanged is called on the adapter. Now, the…
-1
votes
1 answer

call a method from FragmentStatePagerAdapter

I am trying to call a method from FragmentStatePagerAdapter to add and removed tabs. public class TabPagerAdapter extends FragmentStatePagerAdapter { public void removeTab(int position) { new MainActivity().tabLayout.removeTabAt(1); …
choman
  • 787
  • 1
  • 5
  • 24
-2
votes
1 answer

Viewpager does not redraw contents correctly IndexOutOfBoundsException: Invalid index 3, size is 2

I am developing android app that has four pages slider.I have one activity that contains viewpager and four fragments. When i open slide second time it loads only first two slides out of four and showX Invalid index error.I used…
-2
votes
1 answer

ViewPager obj is null even though it initilized correctly and also present in the defined layout xml

Before posting I checked many questions but they didn't helped me. Most of the answers says that the ViewPager is in different layout, so that is why it generating null pointer exception. Below is my stacktrace E/AndroidRuntime: FATAL EXCEPTION:…
-2
votes
2 answers

View Pager context issues

Within my MainActivity, I am trying to get the context of a control (spinner) that is located on a fragment. I am using a FragmentStatePagerAdapter to manage the fragment(s). The last line of my onCreate() throws the exception because the mSpinner…
1 2 3
26
27