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

IllegalStateException during OnPageScrolled ViewPager Android

I am trying to make an infinite scrolling carousal using the following link here Now I used this and modified as I wanted. But something went really wrong and I can't fix it. Here is my code: package com.greycodes.orissatourism.destinations; …
0
votes
2 answers

Getting a Fragment inside a ViewPager in Android using getRegisteredFragment returns null

I've been searching a lot and I can't make it work. I have a problem trying to get fragments inside a viewpager with a tabstrip. I've implemented a SparseArray as I read here and several methods that I found here but I can't make it work. The thing…
0
votes
1 answer

One directional ViewPager

I'm trying to create an app where users can swipe through a deck of photos. After swiping left or right, the previous photo should be deleted and the next photo is shown. Android's ViewPager seems ideal for this except it models a slideshow rather…
0
votes
0 answers

Efficiently using FragmentStatePagerAdapter

I have an activity, inside which there is a SearchView and a ViewPager. If a user enters a string of length n0 , where n0 > 0, in the SearchView and presses search, then the ViewPager will show n0 fragments. If a user subsequently searches another…
0
votes
1 answer

Struggling with a top level FragmentPagerAdapter containing a Fragment with its own FragmentPagerAdapter

Have a 2 level UI, The top level has a tab strip powered by a FragmentPagerAdapter. One of the fragments in turn has a 2nd level FragmentPagerAdapter and its own tab strip carrying a couple of "sub"fragments. Now, the sub fragments display when the…
0
votes
1 answer

Lost Data from expandablelist view when pages are swiped

I am using an expandable listview inside viewpager. Each page has expandablelistview. When clicked on, it will show the child view. Each child view has two button and 1 textview. The buttons are used for set value to textview eg.…
0
votes
1 answer

FragmentPagerAdapter saves his state, but it should not

I have a strange "bug" in my app. Here is the construction: We have a NavigationDrawer with several Fragments (like every app does). Some fragments (e.g. Canteen-Frag) contain a ViewPager with a FragmentPagerAdapter. As everyone knows, the ViewPager…
0
votes
0 answers

Have per-fragment properties accessible after the fragment is destroyed (FragmentPagerAdapter)

My app has a sliding tabs setup, and each tab is a Fragment handled by an extension of FragmentPagerAdapter. I'm looking for a way to set a value associated with each fragment, while being sure that I can access those values regardless of whether or…
Noah Andrews
  • 353
  • 2
  • 14
0
votes
2 answers

java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.support.v4.app.Fragment

I get this error java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.support.v4.app.Fragment when I try to open my activity CuteCollection.java in my app. The strange part is that when I click on the first line…
0
votes
2 answers

Android FragmentPagerAdapter detect if user has visited a specific tab

I have multiple tabs using FragmentPagerAdapter but the ViewPager creates a page before and after my current tab and the OnCreate() method gets called even when I'm not on that tab. It becomes really difficult to run a specific operation on a…
0
votes
2 answers

Passing position as an argument to Fragment In FragmentPagerAdapter

The getItem() position is not always right! Sometimes it will show 0,1,2,3,4 then if I go back it shows a different position (4,2,3,1,0). What is the proper way to use "position", if I need the position to pass into an arraylist/treemap??? 02-18…
Petro
  • 3,484
  • 3
  • 32
  • 59
0
votes
1 answer

viewPager with tab in android

hi i have a fragmentAdapter: public class TitleAdapter extends FragmentPagerAdapter { private final String titles[] = new String[] { "Home", "Eventi"}; private final Fragment frags[] = new Fragment[titles.length]; Context context; …
0
votes
0 answers

noclassdeffounderror with FragmentPageAdapter

I'm trying to implement swiping on a group of fragment in my app and am basically trying to follow the code on Android's http://developer.android.com/reference/android/support/v13/app/FragmentPagerAdapter.html page. However, I'm getting the…
0
votes
1 answer

ViewPager refreshing itself

Am running in some weird problem. I have implemented ViewPagerTabStrip by following the tutorial Here It's working fine and i have implemented Three Tabs. On the first Page /tab , i am loading the data from server & displaying it in the…
Sandip Fichadiya
  • 3,430
  • 2
  • 21
  • 47
0
votes
1 answer

android disable fragment 0 in fragmentpager

I'd like to be able to not allow switching to one of my 3 fragments in my custom FragmentPagerAdapter when certain conditions are met. Unfortunately I failed to find any help. I'd prefer to not remove and re-add the fragment (item 0), as this…
Lance Toth
  • 430
  • 3
  • 17