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
2
votes
1 answer

Using FragmentStatePageAdapter to retain position for fragment with ViewPager

I have an activity that contains a TabLayout and uses a fragment for each tab. In return, that fragment contains another fragment for use with ViewPager. This is my setup: RoutineActivity.java public class RoutineActivity extends AppCompatActivity…
2
votes
0 answers

How to removing an old fragment bundle cache permanently?

Even when I return POSITION_NONE, while using FragmentStatePagerAdapter, I can see that it removes my fragment and creates the new instance. But the new instance receives a savedInstanceState Bundle with the state of an old fragment. How can I…
2
votes
3 answers

how to retrieve the firebase database values only once without listening to childvalues even though they have changed

I have this scenario where in my app i am trying to query the child nodes and pass it on the list to recyclerview adapter and here comes the problem when i am scrolling up the recycler view items and if some one has inserted a post, my recyclerview…
2
votes
1 answer

Update ViewPager total pages and set current item without reloading

I'm sorry if the title is ambiguous as I don't know how to describe my problem in a short way. I'm using ViewPager with FragmentStatePagerAdapter to display a list of posts of a forum's thread. Each page of the ViewPager is corresponds to a page…
2
votes
0 answers

FragmentStatePagerAdapter takes few seconds to load fragment

I am using FragmentStatePagerAdapter, in that i have 7 pages. If i open any activity from one of these fragments then it gets opened instantly. But if i try to click on back press. Then opened activity takes few seconds to kill that activity and…
Harneet Kaur
  • 4,487
  • 1
  • 16
  • 16
2
votes
3 answers

ViewPager + RecyclerView issue in android

Hi I have Tablayout with Viewpager and i am using Fragment for tablayout. Now in every Tablayout fragments I have Recyclerview and displaying items.Please See this my json response http://pastebin.com/nUswad9s here in "typeMaster": array i have…
2
votes
2 answers

Issue with ViewPager and FragmentStatePagerAdapter when activity is destroyed

I have an activity which creates viewpager adapter (FragmentStatePagerAdapter) and sets the viewpager to this adapter. This is how viewpager adapter is created and is set to the viewpager widget. viewPageAdapter = new…
Ritt
  • 3,181
  • 3
  • 22
  • 51
2
votes
0 answers

Don't restore ViewPager when Activity is restored

The setup of my project is as follows Activity has Fragment and it has ViewPager with pages supplied by FragmentStatePagerAdapter. The data displayed by ViewPager is fetched from network. When Activity is destroyed and restored, it tries to restore…
2
votes
2 answers

FragmentStatePagerAdapter - getItem

I know there are several other posts on this topic, but I wanted to paste my code because I believe there may be an error in it that is causing my problem. My FragmentStatePagerAdapter is returning the wrong position, and I am not sure why. Here is…
Phil
  • 4,029
  • 9
  • 62
  • 107
2
votes
1 answer

ViewPager + FragmentStatePagerAdapter not working as intended

There are a lot of similar question but none of them solved my problem. I got nested ViewPagers and nested FragmentStatePagerAdapters in my application. In details, a first ViewPager (backed with a 4 fragments adapter) is created, the first fragment…
2
votes
1 answer

Android - Middle Tab Error in TabLayout in Fragment

I am having an issue in one of my fragments which contains a TabLayout. The TabLayout and the data inside each tab works fine but I still get a moveToState error (This error does not come up when I switch between the first and last one, only from…
2
votes
2 answers

FragmentStatePagerAdapter first call to getItem wrong with sdk 22-->23 upgrade

UPDATE 2: Getting rid of all v4 support references fixed it. UPDATE: I started from scratch to see what triggers this behavior. It occurs once I add a check for location permissions. I can't go backwards -- even when I strip out all the permissions…
2
votes
2 answers

How to clear fragment backstack till a specified fragment?

I am working on an application that has tabs with viewpager. I am using fragmentstatepageradapter for handling the viewpager tabs. I am replacing the first fragment with nested fragments using the childFragmentmanager and adding the current fragment…
2
votes
1 answer

Duplicate Menu and Data in Fragments after using FragmentStatePagerAdapter

I tried so many answers provided by various posts here but nothing worked for me. Problem- I have navigation drawer that has 6 fragments but single activity. Everything worked fine till I changed 1st ranked fragment in drawer. I wanted Swipe tabs…
Roon13
  • 387
  • 2
  • 23
2
votes
0 answers

Can we change the setOffscreenPageLimit() of ViewPager dynamically in Android?

I am using FragmentStatePagerAdapter along with ViewPager to hold my fragments. User will have one image by default and he can keep adding upto 10. When I add 10 pages, I am seeing lots of OutOfMemory issues at different places in my app code, most…
cgr
  • 4,578
  • 2
  • 28
  • 52