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

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter? About FragmentPagerAdapter Google's guide says: This version of the pager is best for use when there are a handful of typically more static fragments to be paged…
83
votes
12 answers

FragmentStatePagerAdapter is deprecated from API 27

FragmentStatePagerAdapter is deprecated from API 27. What's the alternative of FragmentStatePagerAdapter? private class MainPagerAdapter extends FragmentStatePagerAdapter { MainPagerAdapter(FragmentManager fm) { super(fm); } …
MJM
  • 5,119
  • 5
  • 27
  • 53
33
votes
2 answers

remove fragment in viewPager2 use FragmentStateAdapter, but still display

I have a viewPager2 and FragmentStateAdapter, and there are Fragement1, 2,3 4, I am in fragment2, and want to remove fragment3, and display fragment4 after fragment2. The problem is it always show me fragment3(data), the debug shows the fragment3…
25
votes
1 answer

Destroy item from the ViewPager's adapter after screen orientation changed

So I'm having a problem with destroying (removing) one page from the ViewPager after the screen orientation changed. I'll try to describe the problem in the following lines. I'm using the FragmentStatePagerAdapter for the adapter of the ViewPager…
22
votes
6 answers

Fragment no longer exists for key FragmentStateAdapter with Viewpager2

I am using ViewPager2 for my project. I need to use nested fragments inside a fragment with viewpager2. it works like charm until I try to navigate between fragments(not nested ones). After the first time navigating between fragments, the…
21
votes
10 answers

Swipe Direction in ViewPager

I have an Android app that uses ViewPager and FragmentStatePagerAdapter. I however need to add a new feature in which I have to know the swipe direction to move from one fragment view to another, left or right. (i.e, when I swipe left, I would do…
18
votes
2 answers

Android setUserVisibleHint never gets called?

I need to know when my fragment is visible, I was using setMenuVisibility but I now know it's not a good option. I'm trying to implement setUserVisibleHint on a FragmentStatePagerAdapter Fragment, however it never gets called. import…
lisovaccaro
  • 32,502
  • 98
  • 258
  • 410
14
votes
5 answers

FragmentStatePagerAdapter memory leak (nested fragments with viewpager)

I have a "memory leak" in my adapter (quotes will be explained later). I'm currently using nested fragments to host a viewpager. My setup is as following: 1. Activity (Empty activity that hosts Fragment A) 2. Fragment A - fragment that hosts…
13
votes
1 answer

Dynamically skip pages in ViewPager

I got a ViewPager which holds Fragments via FragmentStatePagerAdapter. Let's say the pager initially holds the following pages (Fragments): A - B - C - D When the user swipes, he can move from A to B, B to C etc. But there are cases when the user…
13
votes
3 answers

Load only one Fragment in ViewPager

I have used ViewPager with Fragment.But it loads two pages at time.Is there any way to load only one page in viewpager ?
12
votes
4 answers

Communication between Fragments in ViewPager

I'm trying to do this: http://android-er.blogspot.com/2012/06/communication-between-fragments-in.html Except that I'm using a FragmentStatePagerAdapter I have an Activity with two fragments(FragmentA & FragmentB) FragmentA has an edittext and a…
10
votes
1 answer

Problems using FragmentStatePagerAdapter, Viewpager inside Scrollview

I am using: An activity layout containing fragment added programmatically. Parent fragment has FragmentStatePagerAdapter with view pager, This all content is inside ScrollView. View pager is filled with some child fragments which has…
10
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…
9
votes
2 answers

FragmentManager is already executing transactions

So I have this problem when using the ViewPager with a FragmentStatePagerAdapter AND then I'm trying to select the current page (i.e. show the second page to the user instead of the first one) that I get this exception from time to time. The issue…
breakline
  • 5,776
  • 8
  • 45
  • 84
9
votes
1 answer

ViewPager inside RecyclerView as row item

I need to have an ViewPager (similar to an horizontal gallery) inside an RecyclerView which display an list vertically. Each row of the RecyclerView will have an ViewPager which will allow to swipe between some images. The ViewPager will also…
1
2 3
26 27