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
3
votes
0 answers

Fragmentstatepageradapter replace fragment

I am using viewpager with tabs. I have 2 tabs and each tabs has a listview. I am using fragmentstatepageradapter like that: public Fragment getItem(int position) { switch (position) { case 0: return new fragmenttab1(); …
3
votes
1 answer

nullpointerexception using fragmentstatepageradapter

i am having an issue with an app i am making, everything seemed to be working ok until i started getting an error seemingly out of no where i dont believe i changed any thing from when it was working but every time i open the activity it give me a…
3
votes
1 answer

WebView with FragmentStatePagerAdapter goes blank on calling setCurrentItem

I am working on Swipe Views with Tabs. The code provided in the "EffectiveNavigation" project at the Creating Swipe Views with Tabs page provides a solid starting ground. Experimenting further I added an OnClickListener to the given TextView and…
Ed_Fernando
  • 378
  • 3
  • 12
3
votes
0 answers

Android FragmentPagerAdapter and Fragment's views lifecycle

I have many doubts about how correctly use FragmentPagerAdapter. Not about how to create the adapter or implements the methods, it is more related to how the underlying fragments should manage the instantiated views. In the Android API about…
3
votes
1 answer

View Pager Crash Null Pointer Exception due to navigating back to the old fragment - Android

I am using view pager for navigating between pages. I am using FragmentStatePagerAdapter. I can swipe in one direction with out any problems. But if i swipe back to the older one. Its getting crash. I am getting null pointer exception. 03-12…
3
votes
3 answers

"The specified child already has a parent" error using FragmentStatePagerAdapater

I've tried to implement some of the solutions of all the similar questions but none of them seem to work in my situation. My situation is slightly different because instead of getting the surfaceview from xml I'm creating it through a SurfaceView…
3
votes
1 answer

How to save the state of a fragment in viewpager if I use fragments this way?

I would like to save the state of a fragment in a viewpager. I know that I should do it this way: ViewPager and fragments — what's the right way to store fragment's state? . But I use fragments this way: MyAdapter class MyPagerAdapter extends…
3
votes
0 answers

How to open ViewPager with specified page. (by default it loads 1st 3 pages)

I use the code: pagerAdapter = new BrochurePagerAdapter(getSupportFragmentManager(),params); viewPager.setOffscreenPageLimit(1); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(6); And I see that my Adapter loads Fragments for pages…
Malachiasz
  • 7,126
  • 2
  • 35
  • 49
2
votes
1 answer

Fragment in ViewPager using FragmentPagerAdapter is blank the first time activity is loaded

I'm creating an app with vertical page adapter using FragmentStatePagerAdapter. The big issue i'm facing is, data is not displayed on the textview on first app launch but is displayed on scrolling the page. I believe the fragment view is delaying to…
2
votes
2 answers

IndexOutOfBoundsException when adding items to specific index through LiveData observer

I'm working on a ViewPager fragment that uses FragmentStatePagerAdapter as the adapter. The Adapter's data is a List object that comes from the database, and I am observing the query with MediatorLiveData. MediatorLiveData merges six different…
2
votes
1 answer

Showing pre-selected item in viewpager

I have a gridview. On clicking any item from the gridview , I am going to a viewpager/FragmentStatePagerAdapter with all the items of gridview. I want the view pager to show the selected item. Viewpager is loading the first item always. How to solve…
2
votes
0 answers

FragmentStatePagerAdapter duplicating Fragment's CursorLoader results

I am making a simple news application. Its MainActivity contains a ViewPager with TabLayout that hosts different fragments for news categories. The first two categories are Business (first) Sports (Second). The problem is that the content of these…
2
votes
1 answer

Fragments in ViewPager is not displayer after popBackStack

I have problem: A Fragment is not reattached to its hosting ViewPager after returning from another fragment by using popBackStack. One Activity hosting a Fragment whose layout holds a ViewPager. The ViewPager is populated by a…
2
votes
1 answer

Implementing onSavedInstanceState stops FragmentStatePagerAdapter working

In my activity, I had found I needed to store state for one of my tabs in a tabbed view. This was the result of a search bar, and I needed an Activity to receive and store the data. Although my application was working before hand, when I…
mksteve
  • 12,614
  • 3
  • 28
  • 50
2
votes
1 answer

ViewPager holds fragment's instance even after setting a new adapter

I'm facing some issues with ViewPager and Fragment's instances. I have a ViewPager (let's call Father) with 4 fragments and into the last fragment I have another ViewPager (and call it Child) with dynamic fragments amount. What I mean is that I…