Questions tagged [fragmentpageradapter]

FragmentPagerAdapter is a subclass of the PagerAdapter class from the Android compatibility package that represents each page, in the ViewPager where is used, as a Fragment.

FragmentPagerAdapter represent each page as a Fragment. This adapter class should be used only when there is a limited number of Fragments to swipe in the ViewPager. Using the FragmentPagerAdapter would require at minimum implementing the getItem()(to return the Fragment for this position) and getCount()(to return the number of Fragments in this adapter) methods.


From the documentation of the FragmentPagerAdapter class:

Implementation of PagerAdapter that represents each page as a Fragment that is persistently kept in the fragment manager as long as the user can return to the page.

This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs. The fragment of each page the user visits will be kept in memory, though its view hierarchy may be destroyed when not visible. This can result in using a significant amount of memory since fragment instances can hold on to an arbitrary amount of state. For larger sets of pages, consider FragmentStatePagerAdapter.

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:

602 questions
8
votes
3 answers

FragmentPagerAdapter with ViewPager and two Fragments. Go to the first from the second and update first's text

I'm not familiar with FragmentPagerAdapter, so this is going to be one of those questions that we (you) read the description critically. Structure: I have a FragmentPagerAdapter (code below), that will hold two fragments at a time. The first…
7
votes
0 answers

Same fragment with different contents in viewpager

I have one parent fragment where there is viewpager and tablayout. Viewpager holds the fragment with different contents associated with it. Every think works fine on swipe but whenever I tap on the different tabs of the tablayout, categoryId and…
7
votes
1 answer

updating viewpager with fragments in a new order

I have a ViewPager set up that is drawing the data for its pages (views) from data passed down from a server. On occasion, the server will send down new data that will re-order the views (and sometimes add new views) and I need to make that happen…
7
votes
1 answer

Remove and add page to FragmentPagerAdapter

i am using a fragment pager adapter with 5 pages. and im setting the adapter to view pager as below public class xxx extends FragmentPagerAdapter { final int PAGE_COUNT_LOGGED_IN = 6; final int PAGE_COUNT_LOGGED_OUT = 2; …
7
votes
2 answers

FragmentPagerAdapter getItem error with ListFragment

I've looked at quite a lot of code and can't figure this out. http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html It has to be something simple. I'm showing most of the code. The error is in the next section. …
6
votes
1 answer

Camera SurfaceView flicker in view pager while scrolling

In my App I am using ViewPager with FragmentStatePagerAdapter to display 4 different layout. Layout 1 , 3 , 4 consists of ListView and 2nd layout contains SurfaceView Camera. Now when I am scrolling horizontally camera at the both edges get flicker.…
6
votes
1 answer

Swipe not Working in android ViewPager using FragmentPagerAdapter

I want to create a swipe application for this I am using ViewPager in Android. When I run the code below, it runs successfully and a blue colored Fragment is opened, but swipe is not working on this. Can you tell me why? This is the my Activity:…
6
votes
6 answers

Fragment in ViewPager returns empty object onResume

I use a FragmentPagerAdapter to switch from fragments. I need some functions to be called when a fragmentswitch is made and had some troubles with OnPause and OnResume, so as suggested by THIS question I have implemented an interface…
6
votes
2 answers

How pass fragment arguments while using a view pager with different fragments/layouts?

Objective: To use fragment arguments to pass along the string value from a TextView to a new fragments TextView, BUT while using a ViewPager with different layouts/fragments in the FragmentPagerAdapter. Problem: The new fragment never receives the…
6
votes
2 answers

ViewPager with Nested Fragments?

My problem According to the Google's docs: You can now embed fragments inside fragments. This is useful for a variety of situations in which you want to place dynamic and re-usable UI components into a UI component that is itself dynamic and …
6
votes
1 answer

Binding and unbinding Android Service to/from Fragment (in ViewPager)

I got one single Main-Activity in which I create dynamically Pages inside a ViewPager (via FragmentPagerAdapter). So far so good. Now I got a Service-Implementation I want that activity/those fragments bind to. And this is the point I ask myself…
6
votes
1 answer

Add tabs to the left with FragmentPagerAdapter

This will be the last question I have about tabs, I promise :) (maybe) So from previous questions and try and error I have FragmentPagerAdapter called PagerAdapter which creates a few tabs and also gives me the ability to create new tabs…
6
votes
2 answers

Dynamically change the title of a android.support.v4.view.PagerTitleStrip

I am currentky using a PagerTitleStrip in my application (Doc: http://developer.android.com/reference/android/support/v4/view/PagerTitleStrip.html) Everything works fine, and I have set the title like this: public class PageAdapter extends…
Waza_Be
  • 39,407
  • 49
  • 186
  • 260
6
votes
2 answers

Fragment member variables getting null when accessed in onPageSelected()

I'm using FragmentPagerAdapter with FragmentActivity to create swipe-able Fragments. My first fragment in that pagerAdapter look like this. public class MySummaryFragment extends CommonFragment implements OnPageChangeListener { private Context…
6
votes
1 answer

Android: limit fragments loading with a viewPager

I have 3 fragments that are managed by an FragmentPagerAdapter, set to a viewPager. I want to load fragments one by one, but when the onCreate method of FragmentActivity is executed, the 2 first fragments are executed (onCreateView method). I have…