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

Load same fragment with different data in ViewPager

I have 8 fragments with the same layout in my viewpager. The fragment contains a recycler view and a text view. My problem is that when i initiate the viewpager fragment then all the data gets loaded on the first fragment itself and nothing shows up…
4
votes
3 answers

How to make viewpager transition fast with fragment?

Here i have an questions like how to make view pager fast with fragment. Explanation of what i am doing: I have a fragment which contains five web view and one list view to show the respective data.Based on the content count i am loading fragment to…
4
votes
1 answer

Nested Viewpager Fragment not getting initialized

I have 3 fragments part of a navigation drawer, one of which contains a viewpager. When I first load the app, the viewpager loads all the fragments. However, when I switch to another fragment using the navi-drawer and I switch back, one of the…
4
votes
2 answers

Fragment in ViewPager is not displaying anything in its RecyclerView on rotation

I have 4 Fragments in a ViewPager that is integrated with a TabLayout. Each of those Fragments holds a RecyclerView because I'm displaying an unknown amount of list items. The items are loaded by date, so I have two buttons that let you change days,…
4
votes
1 answer

Android: re-use fragments of ViewPager & FragmentPagerAdapter

I'm using ViewPager and FragmentPagerAdapter within a detail-view. This means I have a list of items and one screen shows the details of a single item. But the user can swipe left and right to navigate through all items. This follows the Google…
4
votes
3 answers

getItem called twice and this causes tab1 and tab2 both executed in FragmentPagerAdapter

I have a swipe tab with three different fragments for three tabs. getItem method in FragmentPagerAdapter called twice. My first tab loads local data and have different layout than next two tabs (tab2, tab3). Tab2 and Tab3 fetches data from server…
4
votes
2 answers

Dynamically adding items to FragmentGridPagerAdapter

I'm trying to display a FragmentGridPagerAdapter with 4 entries, and when the view scrolls I want to add items to the adapter. This is my FragmentPagerAdapter: public class MyPagerAdapter extends FragmentGridPagerAdapter { private final Context…
Robin Eisenberg
  • 1,836
  • 18
  • 26
4
votes
2 answers

Switching tabs not working on click of tabs with PagerSlidingTabStrips

I've integrated PagerSlidingTabStrips in my application which runs as expected on Swipe of tabs. But selecting tabs on PagerSlidingTabStrips doesn't switch to that fragment which works perfectly on swiping between tabs. FragmentManager fm =…
4
votes
1 answer

ViewPager getScrollX return 0 when fragment resumes/recreates

I am trying to create a Velocity View Pager where in I can scroll through pages like a gallery view. I am experiencing problem while doing scrolling calculations. I am using FragmentStatePagerAdapter for ViewPager. For a normal first time run things…
4
votes
2 answers

change FragmentPagerAdapter adapter position on fragment button click

I am working on Android application. In my app I have to use 5 fragment and swipe from fragment 1 to 5. SO I used one FragmentActivity ,FragmentPagerAdapter and 5 fragments. Now I can swipe through all the fragments and can identify the current…
sarath
  • 3,181
  • 7
  • 36
  • 58
4
votes
1 answer

Android - Interfaces and Inner Class

I'm new to Android programming and am trying to figure out how to go about this. I have a fragment that hosts inner tabs, one of them being a ListFragment. On the tabhost fragment I have a button that calls a DialogFragment. When "Yes" is clicked on…
4
votes
3 answers

Android: direct scrolling/ displaying a particular page in ViewPager on button click

I am trying to display a particular page of a ViewPager on button click. It is working but scrolling to that particular page is not smooth i.e. suppose I am at page no. 1 but if I want to go to page no. 5, other pages 2,3,4 also scrolls. I just want…
4
votes
1 answer

How to deal with FragmentPagerAdapter reusing Fragments?

So, I'm trying to use a ViewPager from Android's support v4 library, but there's some serious issues with how it (or FragmentPagerAdapter) deals with Fragments. For instance, I subclassed FragmentPagerAdapter to do the following: public class…
Alex
  • 1,103
  • 1
  • 11
  • 24
4
votes
2 answers

Can't change container ID of fragment

I have a working app which I'm trying to optimise for use on tablet's by inflating a different layout as per the Android documentation. The issue I have is that when in portrait orientation, my view is populated by a ViewPager, and my two important…
Karl
  • 3,394
  • 2
  • 22
  • 31
4
votes
1 answer

FragmentPagerAdapter and FragmentStatePagerAdapter

I am currently thinking which implementation of PagerAdapter should I use. I've got dilemmas connected to both of them. Let me show you what are these. 1# FragmentPagerAdapter Works fine, It creates new instances of fragments when none previous…