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:

391 questions
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,198
  • 1
  • 11
  • 28
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…
8
votes
2 answers

How to avoid recreate Fragment into ViewPager?

I am using a ViewPager with a FragmentStatePagerAdapter that contains 5 pages. In the first page I have a ListView with items. When I change at the last page of the ViewPager, and I come back to first page, my ListView is empty because the Adapter…
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
  • 3
  • 8
8
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…
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,088
  • 1
  • 14
  • 31
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
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,163
  • 4
  • 31
  • 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
0 answers

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…
6
votes
4 answers

ViewPager with different adapters for portrait and landscape

In portrait mode, my ViewPager has 3 fragments A, B, C but in landscape mode, it has only 2 fragments A and C. So I create 2 FragmentStatePagerAdapters for each mode. The problem is when screen orientation changed, ViewPager restores and uses…
5
votes
0 answers

IllegalStateException: Fragment already added: FragmentPagerAdapter

I want to implement bottom navigation using view pager, but my app crashes with the below exception. Not able to find the exact issue here, can someone please help me in this ? java.lang.IllegalStateException: Fragment already added:…
1
2
3
26 27