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
24
votes
4 answers

reorder pages in FragmentStatePagerAdapter using getItemPosition(Object object)

I believe that FragmentStatePagerAdapter does not behave correctly when overriding getItemPosition(Object object) with the purpose of reordering the pages. Below is a simple example. In the initial state, the order of the pages is {A, B, C}. Upon…
UgglyNoodle
  • 3,017
  • 1
  • 21
  • 17
24
votes
6 answers

Android FragmentStatePagerAdapter

I'm working with a FragmentStatePagerAdapter using this example. The MyAdapter class is implemented as follows: public static class MyAdapter extends FragmentStatePagerAdapter { public MyAdapter(FragmentManager fm) { super(fm); …
mraviator
  • 4,034
  • 9
  • 38
  • 51
22
votes
4 answers

How to make PagerAdapter load all pages

I know that by default PagerAdapter loads only the current, next and previous pages. Is there any way to change it, so it will load each and every page? Thanks!
RE6
  • 2,684
  • 4
  • 31
  • 57
20
votes
6 answers

FragmentPagerAdapter Swipe to show ListView 1/3 Screen Width

EDIT: See my answer below--> I am wanting to have a view that when swiped to the right, the listView is shown. Very much similar to what is implemented in the new Google Play Store (Sample image below). I think its a ViewPager but I tried…
20
votes
4 answers

FragmentPagerAdapter - How to handle Orientation Changes?

I use a FragmentPagerAdapter containing several Fragments that need to be notified about changes to the database. I do this by iterating over the fragments, which implement a callback interface, and calling a refreshData() method. This works just…
Philipp E.
  • 3,296
  • 3
  • 34
  • 52
19
votes
4 answers

How do I use FragmentPagerAdapter to have tabs with different content?

I want to have different tabs, where you can swipe through like in the android market. Each tab should use one fragment and use one method for it. This is my FragmentPagerAdapter class: public class SectionsPagerAdapter extends FragmentPagerAdapter…
timolemow
  • 195
  • 1
  • 2
  • 8
18
votes
4 answers

Refresh images on FragmentStatePagerAdapter on resuming activity

I have created an activity that uses FragmentStatePagerAdapter to provide small gallery. However, I can't get it to refresh when activity resumes (after coming back from other activity, for example). Every time first two pictures will be blank, and…
wasyl
  • 3,421
  • 3
  • 27
  • 36
16
votes
1 answer

IllegalStateException: Can't change tag of fragment was android:switcher now android:switcher

My activity uses TabLayout + ViewPager. The number of tabs and pages here are dynamic depending on the data fetch from the server. The crash are reported via Crashlytics, I'm not able to replicate it. My Activity code: @Override protected…
16
votes
4 answers

Design Support TabLayout

I'm playing around with the Design Support Library TabLayout. My problem is that the title of one of the tabs is too long and so, it is drawn on 2 lines instead of 1. I'm wondering if there's a way scale the title text size to ensure that all titles…
16
votes
5 answers

How to add page title and icon in android FragmentPagerAdapter

I want to display title with respective icon in with header page title. like below image, however only able to display title and missing icon. Here is the my sample code,. public class SectionsPagerAdapter extends FragmentPagerAdapter { public…
Horrorgoogle
  • 7,858
  • 11
  • 48
  • 81
15
votes
2 answers

Android - NestedFragments participate in populating the options menu

i am implementing the new nested fragment feature and had stumble into a problem. my view is basically this: a main activity(A) that includes a fragment(B), this fragment(B) includes a pager adapter that has 3 pages each of them is a fragment(C)…
senior
  • 435
  • 5
  • 13
13
votes
1 answer

android.support.v4.app.FragmentPagerAdapter cannot be applied to android.app.FragmentManager

I want to implement just 2 fixed tabs in my application. I followed this tutorial. In my TabPagerAdapter class I'm getting this error : FragmentPageAdapter in android.support.v4.app.FragmentPagerAdapter cannot be applied to…
Nikhil
  • 6,493
  • 10
  • 31
  • 68
13
votes
2 answers

How do I pass a variable through a FragmentPagerAdapter to a Fragment?

I'm an android beginner, trying to learn, and this is my first question, so please excuse me if the question is too simple and please tell me if I'm using the forum incorrectly. I have a FragmentActivity using a layout that includes a viewpager; the…
12
votes
2 answers

ViewPager inside fragment, how to retain state?

In my application the fragment activity holds two fragments, Fragment A and Fragment B. Fragment B is a view pager that contains 3 fragments. In my activity, to prevent that the fragment is recreated on config…
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
12
votes
3 answers

IllegalStateException with PagerAdapter

I am getting an IllegalStateException within this activity but not too sure what is going on. Here is the ViewPagerAdapter class in QuickContactActivity. private class ViewPagerAdapter extends FragmentPagerAdapter { public…
1
2
3
40 41