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

Can't change tag of fragment

I have a few pages (fragments) in a viewPager. When I tried to remove (for instance) the first one, like this: mFragmentManager.beginTransaction().remove(Page1).commit(); It says that IllegalStateException has occured. I don't know why. Could…
5
votes
3 answers

Layout fields of fragment are NULL on initialization

I have issue with passing data to fragments. It crashes 0.1% of all times on production. Let's say on 100k opening of activity it happens 100 times. It looks like not very often, but it very bothering me and I think that I am doing something wrong…
5
votes
0 answers

Implementing MVP with Dagger in a FragmentPagerAdapter

I'm trying to set up a tabbed layout with MVP and having some difficulties. I'm using Google's Dagger MVP sample app as a general reference, and they store the reference to the each presenter in each activity. However, in my tabbed layout, I'm using…
5
votes
1 answer

I've got a weird bug when using a ViewPager inside a Fragment

Okay i'll try and make this as clear as possible. I have a Fragment called CheckerManager which contains a ViewPager. This ViewPager will allow the user to swipe between 3 Fragments all of which are an instance of another Fragment called…
5
votes
2 answers

Android tab click scroll to top

in my app, tabs are implemented using FragmentPagerAdapter public class TabsPagerAdapter extends FragmentPagerAdapter { public TabsPagerAdapter(android.support.v4.app.FragmentManager fm) { super(fm); } @Override public Fragment getItem(int…
Jyothish
  • 587
  • 2
  • 8
  • 24
5
votes
2 answers

How change ActionBar colour when swiping between fragments (Material Design)?

I have an app i am doing, which has a FragmentPagerAdapter setup with 3 fragments to swipe between on the main page. I have been trying to get it setup so as you swipe between fragments, the action bar changes color (fades in and out). However i am…
5
votes
2 answers

Change Tab Programmatically from Fragment with FragmentPagerAdapter

I'm trying to get my app to change from tab 1 to tab 3. The tabs are in a custom TabsPagerAdapter which extends FragmentPagerAdapter. I've tried to change the tab likes this but it causes NullPointerException. Is the mechanism different with a…
5
votes
0 answers

onPause() called at startup

I'm experiencing a strange (maybe it's normal...) behaviour. I've a activity with a viewpager and inside it 3 fragment. I'm using FragmentPagerAdapter and setOffScreenPageLimit = 3. When I deploy the apk to my device (N4) the very first time the app…
5
votes
0 answers

How to change fragment programmatically on FragmentPagerAdapter?

I have created applicaiton by using Eclipse default ViewPager application parameters. Main activity contains 2 tabs(tabA and tabB). Each tab refers to its fragment(fragmentA and fragmentB). public class SectionsPagerAdapter extends…
5
votes
1 answer

ViewPager with FragmentPagerAdapter not displaying

I am using Xamarin and this is my second attempt at getting a ViewPager working. I have created an application from scratch with reference to this web link:…
5
votes
0 answers

ContainerView on UICollectionViewCell

I created a Container View in my iOS App Storyboard. I want to page horizontally in one of the cells in the UICollectionView (like a FragmentPager of Android). However, an error occurs if you put in the Container View in a…
5
votes
3 answers

Dynamically Add and Remove Fragments From FragmentPagerAdapter

I have a FragmentPagerAdapter for a viewPager Which initially has only one Fragment in it. I want to dynamically add a new Fragment to the adapter when user swipes from right to left, and dynamically remove a Fragment when user swipes from left to…
dora
  • 2,047
  • 3
  • 18
  • 20
5
votes
0 answers

Fragment in ViewPager,can not get current Fragment instance

In the class FragmentParentNewsDetail.java,I have a ViewPager,then I use FragmentPagerAdapter to set each page the same Fragment,like this: @Override public Fragment getItem(int position) { String newsId =…
5
votes
1 answer

Update the current fragment in FragmentPagerAdapter

I have a viewPager with tab indicator. The ViewPager is setAdaper with a FragmentPagerAdapter. I have little understanding how the internals of FragmentPagerAdapter work. I noticed that the neighbor fragments are resumed ( OnResume is called ) ,…
Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110
5
votes
1 answer

FragmentPagerAdapter instantiateItem working with Fragments?

i try to get my FragmentPagerAdapter working, but the examples are a bit to easy for real life : @Override public Object instantiateItem(final ViewGroup container, final int position) { final LayoutInflater inflater = (LayoutInflater)…
Kitesurfer
  • 3,438
  • 2
  • 29
  • 47