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

Save and restore instance of Fragment with ViewPager (FragmentStatePagerAdapter)

Short version: I have activity with fragment, which include ViewPager (with FragmentStatePagerAdapter) and on resume to this fragment it recreates. How can I by back press return to Fragment and restore is state and it's Viewpager? Details: I have…
1
vote
2 answers

FragmentStatePageAdapter cache, how do I reference old fragments after activity recreated? (for ex - landscape mode)

In my app I got a ViewPager which is showing 3 fragments in a swipe views layout. If the activity is recreated (for example, if I go to landscape mode) I can't get a reference to the fragments anymore. This is my Adapter public class…
1
vote
1 answer

Dynamically adding/removing pages from FragmentStatePagerAdapter

I was looking at the example of the FragmentStatePagerAdapter at http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html public static class MyAdapter extends FragmentStatePagerAdapter { public…
user1549672
  • 486
  • 1
  • 6
  • 16
1
vote
3 answers

Android: All but first ViewPagers invisible

I am trying to dynamically add View Pagers to my app by inflating XML. All the view pagers and corresponding adapters get instantiated correctly and the required fragments also get attached. However, only the fragments for the 1st view pager are…
1
vote
1 answer

How dynamicaly setText of textview in fragment in FragmentStatePagerAdapter

i want setText of my TextView in fragment of a FragmentStateAdapter in a viewPager when he was created(or page are loaded). I test with a setOnPageChangeListener but it's don't work, so have you idea to how doing this. Bellow my adaptater and how i…
1
vote
1 answer

Android EditText focus inside of Fragment within ScreenSlidePageAdapter

[Using the support library] When attempting to use an EditText inside of a Fragment that is in my ScreenSlidePagerAdapter in which multiple Fragments are visible at once. The second Fragment in the list contains an EditText. On Android 4.1 & 4.2 it…
1
vote
2 answers

Cannot remove fragment from ViewPager, why?

I must be missing something but I cannot remove a fragment from my ViewPager. I store the page titles in an ArrayList: Part of ViewPagerActivity.java (which is a FragmentActivity, the main activity): public static ArrayList mEntries = new…
Jani Bela
  • 1,660
  • 4
  • 27
  • 50
0
votes
0 answers

Add or Remove Tabs based on Switch position

I want to add or remove a fragment from the tab based on switch position if switch is on then the fragment will be added if switch is off then the tab will be removed here is the code i did in the main activity this actually works but only when the…
0
votes
2 answers

How to pass text from one fragment to another? Both hosted by the MainActivity

I have been trying to use Fragments in Android Studio and have been successful in the implementation of it. But, when I am trying to pass any data (Text/String here) I'm getting a Null Pointer Exception. The Fragment doesn't appear to get received…
0
votes
0 answers

Changing theme at runtime from fragment in android kotlin

I have created an activity. The activity's layout contains FragmentContainerView element.
0
votes
0 answers

getting null pointer exception for Bundle.getString while sending data from one fragment to another fragment

I am trying to send the data from one fragment to another using bundle but it is showing me this error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null…
0
votes
1 answer

FragmentStateAdapter and ViewPager2 is loading fragment slower than FragmentStatePagerAdapter and ViewPager

In my app, am showing list of month calendar which can be scrollable to previous and next month. While swiping to previous and next, my fragments are loading smoothly and without any delay if I use FragmentStatePagerAdapter and ViewPager but it's…
0
votes
1 answer

How to get a fragment in FragmentStateAdapter

MyFragment currentFragment = (MyFragment) getSupportFragmentManager() .findFragmentByTag("f"+pagerMainAdapter.getItemId(0)); currentFragment.testRun("Hello world"); I'm trying to Migrate from ViewPager to…
0
votes
1 answer

How to get a fragment using position from a FragmentStateAdapter with ViewPager2

I am using ViewPager2 with FragmentStateAdapter to create a collection of fragments. I want to access a particular fragment on the basis of its position in the Adapter. How can I achieve the same?
0
votes
2 answers

RecyclerView not updated only in adjacent (second) tab of FragmentPagerAdapter

I have a FragmentPagerAdapter (tabFragmentAdapter) with 4 tabs, or fragments. Every fragment has a RecyclerView with adapter. Ever holder is a list of cards that has a remove button. When I press the remove button, the card gets deleted from the…
Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94