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
2 answers

java.lang.InstantiationException: can't instantiate class ... no empty constructor

I have found topics with similar questions like mine but cant find the answer I am looking for so far. my application consists of a FragmentActivity which hosts a ViewPagerAdapter (child of FragmentPagerAdapter) with a fragment in each tab. My…
Panos
  • 101
  • 1
  • 1
  • 4
4
votes
2 answers

Trouble with ViewPager displaying Fragments

I am trying to get a fragment with three tabs displayed using ViewPager. Initially I used to instantiate the fragment from the Activity using FragmentMgr, this worked fine. When I converted this navigation using ViewPager, this Fragment is no longer…
4
votes
1 answer

FragmentPagerAdapter displays all fragment contents on first page

In memory, I have a list of Items, each with a title and a list of 0..N Chunks (which store some information). I know that I am creating this list in memory correctly as I've output the whole structure to the command line. I have an activity that…
4
votes
2 answers

Viewpager and Sherlock Fragments. How to do somethng inside fragment from FragmentActivity?

I have a parent SherlockFragmentActivity class that contains ViewPager with 4 Fragments inside. One of them extends from SherlockListFragment and I want to scroll it to top by click on it's tab. MainActivity class: public class MainActivity…
4
votes
1 answer

Viewpager not retaining views properly

I have a SherlockFragment thats inflating a layout containing a viewpager that allows me to swipe to a number of tab-fragments which I have created. On the first time this fragment gets attached to my activity everything works fine and as expected,…
Nickolaus
  • 4,785
  • 4
  • 38
  • 60
3
votes
2 answers

RecyclerView onClick event is not working with SwipeRefreshLayout?

Before using FragmentStateAdapter. I was using FragmentPagerAdapter then everything was fine but when I migrated from FragmentPagerAdapter to FragmentStateAdapter to reduce memory usage. The issue that I'm facing is that when RecyclerView is at the…
3
votes
1 answer

java.lang.IllegalStateException: Fragment already added: MovieFragment

got error fragment already added on my MyPagerAdapter class which extends FragmentPagerAdapter this is my error logs E/AndroidRuntime: FATAL EXCEPTION: main Process: id.cahyowhy.tmdbmovieimplementation, PID: 8228 …
cahyowhy
  • 553
  • 2
  • 9
  • 26
3
votes
1 answer

Vertical ViewPager with smooth scrolling and page transformation like inshorts app

I wanted to make a Vertical ViewPager looklike inshorts application. I have tried several solutions found on Stack Overflow and in Github. All of them have the same way of implementation of code, and all of them have the same lagging issue while…
3
votes
0 answers

onLoadFinished() not getting called, but onCreateLoader() is called

I am using CursorLoader to load data from database inside my Fragment, which has a RecyclerView. This fragment is being used inside a ViewPager. The ViewPager is contained inside a ContainerFragment, which in turn is inside an Activity. The…
3
votes
3 answers

How to pass data between fragments in FragmentPagerAdapter

For my academic project, I want create an application with 4 tabs. The first one will show recent games added to a list, the second one will be a search form, the third will show the search result, and the last one will show the details. I currently…
3
votes
4 answers

How to make viewpager to not load pages again if they are already loaded

I have Viewpager with 7 tabs, like in play store if we tap on tab on main screen it loads and if we tap that tab again it does not, I want if i tap on tab 1 it should load then i lets tap on tab 7 and then i tap tab 1 again it should not load, and…
3
votes
1 answer

Take focus away from tabs in ViewPager/TabLayout

I am using ViewPager/TabLayout on Android TV, and I have 2 questions. 1) Currently, if I press DPAD_UP, the focus goes to the tabs, but the page does not actually change to the one corresponding to the focused tab until DPAD_CENTER is pressed. So,…
3
votes
1 answer

getPageTitle not being called in FragmentPagerAdapter

I have a FragmentPagerAdapter which handles getting the current fragment, keeping track of the number of tabs and setting the tab title for each tab. public class ClothingSectionsPagerAdapter extends FragmentPagerAdapter { private String[]…
Tom Finet
  • 2,056
  • 6
  • 30
  • 54
3
votes
3 answers

Why should I use FragmentPagerAdapter instead of FragmentStatePagerAdapter?

I've been searching for it and all I found was the difference between them. And that's not the point. If you use FragmentStatePagerAdapter in a ViewPager, you'll end up doing the same as you'd do with FragmentPagerAdapter, but consuming much less…
3
votes
2 answers

android only show first viewpager inside recyclerview

i have a viewpager with FragmentStatePagerAdapter inside recyclerview and its show only the first row in recyclerview please help me viewpager adapter: public class CustomPagerAdapter extends FragmentStatePagerAdapter { private static…
tom
  • 31
  • 2