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
2
votes
1 answer

Running database query in FragmentStatePagerAdapter NPE

I am trying to run a query against my database to get some data (which changes page to page) from my database. I am getting a NullPointerException at Double balance = db.getSum(); Below is the full code of my fragmentstatepageradapter import…
2
votes
0 answers

FragmentStatePagerAdapter getItem method is not called after orientation was changed

I have activity and 3 fragments. I use PagerSlidingTabStrip for suport tabs. Adapter: public class MyPagerAdapter extends FragmentStatePagerAdapter { ... @Override public Fragment getItem(int position) { switch (position) { …
vetalitet
  • 703
  • 2
  • 10
  • 25
2
votes
0 answers

How to preserve manually set InstanceState of ViewPager Fragments (in depth explanation)?

I have a ViewPager (instantiated with FragmentStatePagerAdapter) with some Fragment attached to it. In a specific usecase I need to reset instanceBean and UI for most of the fragments in the pager. After some googling I have tried some solutions…
2
votes
3 answers

ViewPager NullPointerException when scroll back

I have an horizontal ViewPager (let's call it A) that contains a fragment in each page. Each fragment has a vertical ViewPager (let's call it B) and each page contains a fragment with one image. When I scroll A to the right everything works fine but…
2
votes
2 answers

Android ViewPager get view nullpointer exception

I have support.v4 ViewPager, which I fill with fragments, by using FragmentStatePagerAdapter. The displaying of the fragments in ViewPager works as expected, but the problem is getting the fragment views when calling the getView() function in the…
2
votes
1 answer

PagerAdapter getCount() is called many times

I am using FragmentStatePagerAdapter. for some reason the getCount() method is beeing called a lot of times before any fragment is even visible... Is it a normal behavior?
roiberg
  • 13,629
  • 12
  • 60
  • 91
2
votes
4 answers

IllegalStateException: Fragment already added - during app startup on Android OS 4.3

My Android app has a single activity with a tab controller hosting 4 tabs – each tab is represented by a Fragment. When I run the app on my test device running OS 4.03, the app works and I can navigate to different tabs, etc. When the app is run…
2
votes
2 answers

FragmentStatePagerAdapter fails to load the fragments again when I get back to old instance of the parent Fragment

Scenario: I have a fragment which has a ViewPager which contains 5 instances(different) of a single Fragment with different values, each having a listivew that contains some sort of items. Problem: The flow goes smooth when I click an item of…
2
votes
0 answers

FragmentStatePagerAdapter - Reset data set

This is the scenario: the adapter already contains data i need to clear the old data set and add a new one fetched from the server The 'clear()' works removing all the items but then the adapter gets re-populated with the old fragments instead of…
2
votes
0 answers

Call method on all Fragments in FragmentStatePagerAdapter

I have a ViewPager that pages through ListFragments. Each page is a specific date and the list in each page contains items in mulitple categories. The user can at any moment toggle the displayed categories through a dialog. This is not a problem for…
2
votes
1 answer

Jump to the next fragment on any fragment in FragmentStatePagerAdapter

I am using a FragmentStatePagerAdapter in my app. this is my adapter: private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { List posts = FeedListFragment.getPosts(); public…
roiberg
  • 13,629
  • 12
  • 60
  • 91
2
votes
3 answers

How to create a carousel using viewpager and fragmentStatePager Adapter

I am new to android and i am trying to create a carousel in android. My class structure are as follows public class PageViewActivity extends FragmentActivity { ViewPager pager; ... public void onCreate(Bundle savedInstanceState) { …
2
votes
0 answers

nested fragment + FragmentStatePagerAdapter

I'm trying to use a Fragment(parent fragment) with a View-Pager using the FragmentStatePagerAdapter (because dynamically adding fragments) having videos fetched from the you-tube in different pages of the view pager. when you-tube video is clicked…
2
votes
0 answers

Delay showing content in Fragment Pager Adapter

I'm using FragmentPagerAdapter has 5 tabs. In tab number 3 I'm showing data in listview from web service and it showing successfully. When I swipe to tab 2, 4 and return to tab 3, the data is still showing in listview. If I swipe to tab 1, 5 and…
bebosh
  • 806
  • 10
  • 25
2
votes
2 answers

class not found exception android for fragment activity

I am working on fragment activity to work on gingerbread OS. when I am trying to run the application on gingerbread emulator the application is getting forced close due to ClassNotFound error. I am providing my main fragment activity code below A…