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
2 answers

Replacement for BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT

androidx.fragment.app.FragmentStatePagerAdapter is deprecated and developers are urged to switch to androidx.viewpager2.adapter.FragmentStateAdapter How can we get the same functionality with FragmentStateAdapter that…
3
votes
2 answers

FragmentStateAdapter removing last tab instead of current ViewPager2

ViewPager2 is removing last tab instead of current tab, same problem was occurring when i was using viewpager. Also when selected tab is last one it removes last tab correctly dependency implementation…
3
votes
2 answers

Problems when reloading fragment in ViewPager

I have problem with fragments in ViewPager. In my app I have 4 tabs implemented with FragmentStatePagerAdapter. Here is my SectionsPageAdapter.java public class SectionsPageAdapter extends FragmentStatePagerAdapter { private String fragment0 =…
3
votes
2 answers

Populating TabLayout using FragmentStatePagerAdapter with only selected items

I am using Android TabLayout to generate tabs with FragmentStatePagerAdapter as adapter. Now with this code it generates the items on every tab when I scroll it. SongManager.getAudioListFromResponse(result) gives a List of Audio objects which each…
3
votes
0 answers

How to properly implement infinite scrolling by dates with Android ViewPager and FragmentStatePagerAdapter?

I'm working on a simple Android application (to-do list), and I'm stuck on attempting to implement a ViewPager using a FragmentStatePagerAdapter to navigate through days with tasks. For simplicity I added some tasks for current day, day before, and…
3
votes
3 answers

FragmentStatePagerAdapter is not calling getItem()

i have seen the relative post to my issue but, it's not solve my probleme. I'm trying to get a swipe view with 3 fragment. In the main fragment i have this: public View onCreateView(LayoutInflater inflater, ViewGroup container, …
Arka-57
  • 41
  • 5
3
votes
3 answers

Why should I use FragmentPagerAdapter instead of FragmentStatePagerAdapter?

I've been searching for it and all I found was the difference between them. And that's not the point. If you use FragmentStatePagerAdapter in a ViewPager, you'll end up doing the same as you'd do with FragmentPagerAdapter, but consuming much less…
3
votes
0 answers

Android - ViewPager + FragmentStatePagerAdapter + PageTransformer

In my app I use a ViewPager in conjunction with PageTransformer to display some data list as a card deck. That list is sometimes refreshed and it contains plenty of items in a common case, so I use FragmentStatePagerAdapter with needed page…
3
votes
2 answers

TransactionTooLargeException when using FragmentStatePagerAdapter and launching a new activity

This is actually a problem that stemmed from somewhere else, but I have narrowed it down to the following scenario. In my MainActivity, I use a ViewPager to have three tabs on the bottom to swap through my three Fragments. If I click a button to…
3
votes
1 answer

ViewPager Shows Wrong Content after Removing a Page

I have created a ViewPager implementation with FragmentStatePagerAdapter to let the user of my app browse through and edit a potentially large number of records. The parent activity's menu includes a delete button, which allows the user to remove…
3
votes
0 answers

Infinite FragmentStatePagerAdapter with different fragment classes

I came across a strange issue in my project. I have implemented infinite viewpager adapter using FragmentStatePagerAdapter Code for same is: public class DashBoardAdapter extends FragmentStatePagerAdapter { ArrayList
3
votes
0 answers

How to make the video in view pager stop playing when the next page is scrolled?

First, I play a video in the first view pager, then when i scroll to the next page, the video continues to playing. The video stops when i come to the third page. Is it any coding to stop the video or the activity by the time I scroll to the next…
3
votes
2 answers

Fragment becomes blank after asking for runtime permission

I am working on viewPager with fragment and it was working all things perfect before I have start implementing runtime permission for different module. Here is my viewPager Adapter. public class DashboardAdapter extends FragmentStatePagerAdapter…
3
votes
1 answer

Prevent FragmentStatePagerAdapter from creating new fragments when viewpager is swiped next or previous

My current implementation of FragmentStatePagerAdapter creates new fragments every time it is called by viewpager. I Want to save states of fragments which are previously loaded and wnat to reuse them. I think to achieve this I have to implement…
3
votes
4 answers

FragmentStatePagerAdapter handling getItem() position

I tried this, but wrong lists get binded to the recyclerview. I tried SparseArray as well, even that doesn't work. getItem() gets called twice when i start Mainactivity. How do I handle the position returned? I tried returning viewpager currentItem,…
Anirudh
  • 2,767
  • 5
  • 69
  • 119