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
1
vote
0 answers

How to deal with the error: "Design assumption violated." when using FragmentStateAdapter

Hi guys I am using ViewPager with FragmentStateAdapter. I have an option for the user, in one of the added fragments, to recreate the activity (a method calls: activity.recreate()). However if the activity is recreated I get the following…
1
vote
1 answer

ViewPager2 with FragmentStateAdapter nested scrolling issue

I've setup my activity layout using ViewPager2, BottomNavigationView and Fragments. In my First fragment in ViewPager2 contains a ImageSlider. When I scroll the ImageSlider the entire fragment (in ViewPager2) scrolls to 2nd Fragment. Why is this…
1
vote
0 answers

Fragment is null while using FragmentStatePagerAdapter

I have 3 bottom navigation tabs in my application : Home MyTour Profile In MyTour, I am using MyTourFragment which have 3 different tabs : Pending(0) Success(1) Failed(2) For all three tabs(Pending, Success, Failed) I am using…
Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
1
vote
1 answer

Switch to Fragment through swipe up/down

I'm having some trouble with implementing a certain feature within my app. What I would like to achieve is being able to swipe up/down to see certain fragments. I am currently using a ViewPager to scroll horizontally through three Fragments, using…
1
vote
1 answer

Destroying a ViewPager

I'm trying to clone the TikTok app. For the home screen, I made a VerticalViewPager (Custom view pager) with a like button, title, and comments. I'm retrieving videos from Firebase. TikTok model has a video URL, title name, and the number of likes.…
1
vote
1 answer

Exoplayer - How to play only the current screen visible in FragmentStatePagerAdapter?

I am using FragmentStatePagerAdapter with Exoplayer. My main goal is to load the next page, however don't play the video in that page. Right now in my VideoFragment for the viewpager, I am playing the video inside onCreateView player = new…
1
vote
1 answer

Getting current fragment variables values

I am using FragmentViewPagerAdapter to create a calendar Activity. Each fragment represents a day, and I have a Switch on my main activity that allows the user to filter results on each fragment. I am using ViewModel to request data, so when the…
1
vote
0 answers

FragmentStatePagerAdapter giving blank fragments after updating

I have an Weather adapter to show the weather, the activity is split into two screens, one half a listview (different adapter), the other is tablayout with another tablayout inside to scroll through all the different pages of weather that are…
Brandon
  • 1,158
  • 3
  • 12
  • 22
1
vote
0 answers

FragmentStatePagerAdapter not refreshing fragments when notifyDataSetChanged is called

I am trying to implement a dynamic list update to FragmentStatePagerAdapter. I have a list of few fragments which have radio buttons, edit text, and different other fragments having just a single view. Now the logic revolves around radio button…
1
vote
0 answers

how to remove the pager fragment from activity to prevent the old fragment instance to be restored by os

It is an activity hosting a pager fragment which has android.support.v4.view.ViewPager and the adapter class derived from FragmentStatePagerAdapter. The problem is from the pager fragment it has two or three fragments cached, but the data is not…
lannyf
  • 9,865
  • 12
  • 70
  • 152
1
vote
1 answer

How to initialize my ViewPager

I have an Activity A which contains a list and an Activity B which displays the detail of an item from activity A using a fragment. There is a ViewPager in Activity B, which allows me to swipe left and right to view different item details in the…
Louise L.
  • 797
  • 1
  • 6
  • 10
1
vote
0 answers

Hide/show fragments in single ViewPager window

How can I hide SearchFragment and display ChatFragment, without remove() in ViewPager? I had no issues with creating new instance everytime, but I don't want onDestroy() to have place, since i will be switching these 2 views very frequently. I want…
1
vote
0 answers

How to deal with a viewpager's FragmentStatePagerAdapter's bug on reordering fragments?

I think I've come across the bug of FragmentStatePagerAdapter as below: https://issuetracker.google.com/issues/36956111 I've tried many solutions I found on the web but they didn't work well. Just want to ask if you guys have any solutions on that…
im_chc
  • 1,023
  • 15
  • 24
1
vote
3 answers

Display Android Toast message in FragmentStatePagerAdapter

I'm trying to display a toast message in a FragmentStatePagerAdapter, which I'm failed. I need to get context to insert in my code Toast.makeText(, "The message", Toast.LENGTH_SHORT).show(); But I can't use getContext(), getActivity() cause I don't…
Ghasem
  • 14,455
  • 21
  • 138
  • 171
1
vote
1 answer

Ondraw Method doesnt call Using Viewpager & FragmentStateAdapter

I use a Custom Calendar View using Viewpager - FragmentStateAdapter - Fragment - Viewgroup -view I can get first fragment and second fragment when I swipe page, but third fragment doesn't show anything. so I debug and get draw() method doesn't…