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
387
votes
7 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…
68
votes
10 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
  • 4,870
  • 4
  • 22
  • 49
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…
21
votes
1 answer

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…
20
votes
9 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
  • 27,544
  • 92
  • 235
  • 388
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
3 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…
12
votes
2 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…
12
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…
11
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…
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…
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,703
  • 3
  • 34
  • 51
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,278
  • 2
  • 23
  • 43
1
2 3
26 27