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
9
votes
2 answers

ViewPager first fragment shown is always wrong with FragmentStatePager

I am trying to have the same view pager + tabs design as the PlayStore 5.1.x. Here is my layout :
S.Thiongane
  • 6,883
  • 3
  • 37
  • 52
9
votes
2 answers

App crashes when assigning new adapter to my ViewPager

I have a ViewPager which is populated by a FragmentStatePagerAdapter when the app starts: ViewPager mViewPager; ... @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view,…
user1567896
  • 2,398
  • 2
  • 26
  • 43
9
votes
1 answer

Android: ViewPager FragmentStatePagerAdapter get current View

Question: How to get current View of a ViewPager FragmentStatePagerAdapter? I have spent almost 24 hours on this and searched everywhere for the fit solutions. Get current position is easy, I already got that. This is get current…
jerrytouille
  • 1,238
  • 1
  • 13
  • 28
9
votes
1 answer

Refreshing Fragment View while using FragmentStatePagerAdapter

Seems the refresh issue is discussed before, but none of the solutions worked for me. What I am trying to do: I am using FragmentStatePagerAdapter. Each position of the adapter holds a fragment that has a linear layout that has chess like…
9
votes
1 answer

Fragment getView() always returning null for Fragments created by a FragmentStatePagerAdapter

I have been reading a lot about fragments. Have found other people having problems retrieving fragments view because null was always returned but no answer solved my problem. What I'm trying to do is create a image gallery. I have a Fragment that…
Notbad
  • 5,936
  • 12
  • 54
  • 100
8
votes
2 answers

Remove all fragments from ViewPager populated by FragmentStatePagerAdapter

I have a ViewPager that I am populating with fragments(representing objects from arrayListOfObjects) using FragmentStatePagerAdapter. All works well: mMyFragmentPagerAdapter = new fragmentAdapter(getSupportFragmentManager(),orientation …
ngwane
  • 133
  • 1
  • 4
  • 8
7
votes
1 answer

Save/Update Fragment's EditText data in a FragmentStatePagerAdapter

Introduction I have an activity with a Book that contains an arraylist of type "page" and to handle all the pages I decided to use a FragmentStatePagerAdapter in which one of my fragment contains one page. I created an interface for the…
7
votes
1 answer

Android - Attempt to invoke virtual method 'void android.support.v4.app.Fragment.setMenuVisibility(boolean)' on a null object reference

Here is the full stack trace of the error: http://pastebin.com/5dQHkUw3 The error started to appear only after I started using fragments in the project, because I want to give JSON feeds. It was fine before when I was creating Tabs, NavigationDrawer…
7
votes
2 answers

Android FragmentStatePagerAdapter returns blank screen when reloading middle fragments

I'm trying to make an app with 4 tabs using FragmentStatePagerAdapter and a ViewPager. When I first run the app and if I select the tabs in order (0 to 3) everything goes fine, then if I try to perform the way back (3 to 0) tab 1 shows a blank…
7
votes
1 answer

how to add page dynamically in FragmentStatePagerAdapter

I know this question asked many time but I don't get answered after many research. in my main activity I have a view pager and I set an adapter for that: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
Saber Solooki
  • 1,182
  • 1
  • 15
  • 34
7
votes
1 answer

getResources from FragmentStatePagerAdapter

Inside an activity class, I have this class (from android samples): public static class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter { public DemoCollectionPagerAdapter(FragmentManager fm) { super(fm); } …
6
votes
1 answer

Camera SurfaceView flicker in view pager while scrolling

In my App I am using ViewPager with FragmentStatePagerAdapter to display 4 different layout. Layout 1 , 3 , 4 consists of ListView and 2nd layout contains SurfaceView Camera. Now when I am scrolling horizontally camera at the both edges get flicker.…
6
votes
6 answers

ViewPager not getting updated using FragmentStatePagerAdapter

I've a two fragments, Fragment A and Fragment B. Fragment A lists all products and Fragment B shows detail about the product and its images. Fragment A calls Fragment B and Fragment B fetches data from web service and sets to ViewPager using…
moDev
  • 5,248
  • 4
  • 33
  • 63
6
votes
2 answers

Adding Fragments Dynamically on both side of the ViewPager using FragmentStatePagerAdapter

In one of my apps, I need to add Fragments on both sides of the ViewPager. First of all, I will get a constant of 5 feeds, and my ViewPager will show feed at index 2 i.e. my current displayed Fragment will contain data present at index 2. So overall…
6
votes
1 answer

FragmentStatePagerAdapter not calling getItem

The problem: I have a ViewPager setup with a FragmentStatePagerAdapter that uses a global arraylist for the contents of its fragments. When I want to update this global array, I simply call the arraylist.add() method, instantiate a new…
1
2
3
26 27