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

Viewpager implementation using Android-Studio fails

I get this error when I try and create a ViewPager for an Activity: FATAL EXCEPTION: main java.lang.NullPointerException at com.blutech.viewpager.PlaceHolderFragment.newInstance(PlaceHolderFragment.java:44) at…
0
votes
2 answers

Possible to have a FragmentPagerAdapter inside Fragment which is a part of FragmentActivity?

I am developing an android application in which I have many fragments inside one fragment activity. I have a new fragment now inside which there is a call to a fragmentpageradapter. This however throws a null pointer exception. Is it possible to do…
4kshay
  • 231
  • 4
  • 11
0
votes
2 answers

FragmentActivity not showing the right layout for the fragment

I am trying out Fragments in android for the first time, I am using a FragmentPagerAdapter for a finite number of fragments, in this case 3. The only problem is that when I swipe, it goes to the second and third page, but shows the layout for the…
0
votes
0 answers

Want to use listview under pager adapter in android

I am new in android development. In my application I am using a PagerAdapter, and want to implement list view in one tab. Which class extends fragment , with custom adapter. There is one layout for list view and one block for the list module. Here…
Dhiman
  • 146
  • 1
  • 5
  • 21
0
votes
2 answers

ViewPager unable to load images lazily with Picasso

I have a FragmentActivity in the first tab of a TabHost, and the FragmentActivity itself holds a ViewPager. The ViewPager's setAdapter() method sets a FragmentPagerAdapter with a set of Fragments. The goal is to have swipeable images in the first…
0
votes
1 answer

ViewPager with tabs stackoverflow

i have a viewpager and i have four tabs. i have these codes (just like google's tutorial) in my adapter: @Override public void onPageSelected(int position) { mActionBar.setSelectedNavigationItem(position); } @Override …
0
votes
1 answer

FragmentPageAdapter not working properly

I am using FragmentPagerAdapter to navigate between 4 Fragments in my app. But I am facing a strange problem. When I debugged my App I found that the Index value in the getItem loads to 0 when MainActivity is started and so the Fargment at 0th index…
Puneetr90
  • 199
  • 1
  • 6
  • 18
0
votes
2 answers

How to avoid creating first fragment before setCurrentItem?

I am using FragmentActivity and ViewPager to show several fragments.I want to show different fragment each time according to the intent passed to the FragmentActivity.But the problem is when I use setCurrentItem() after setAdapter(), the first…
0
votes
1 answer

How to update Fragment Pager Adapter from Fragments?

Problem :: I have one SherlockFragmentActivity in which i have added six fragments. Now out of six 3 fragments are added based on the conditions. loading the fragments :: private void loadFragments() { try { dataHelper=new…
0
votes
3 answers

refreshing listView of a fragment from MainActivity

it is really strange, many people has asked this question but not even one useful answer I have a MainActivity class public class MainActivity extends FragmentActivity implements ActionBar.TabListener with 3 actionbar tabs (sections 1,2,3) each…
0
votes
1 answer

getActivity() returns null in ActionBar Fragment

getActivity() within a Fragment will return null if called before fragment.onAttach(activity). fragment.onActivityCreated(savedInstanceState) is called after fragment.onAttach(activity). See developer.android for info on fragment lifecycyle. I have…
Eric H.
  • 6,894
  • 8
  • 43
  • 62
0
votes
2 answers

How to update controls in all tabs created using FragmentPagerAdapter?

I have created a tabbed android application using android.support.v4.view.PagerAdapter. There are about seven tabs in the application and I plan to add more. Each tab contains a lot of controls (TextView, Spinners, Toggle buttons, Check boxes…
0
votes
2 answers

Restoring a fragment using FragmentPagerAdapter

I have an application using two tabs, both containing fragments. I am using the FragmentPagerAdapter to manage tab changes. All works fine with two tabs. I recently added a third tab and am having a bit of trouble. tab1(fragment1) is a…
0
votes
1 answer

Fragments in a ViewPager – Tapping a button inside current frag effects the fragment after it NOT the current/visible frag

Problem: Upon clicking a button in a fragment inside of the ViewPager the click falls through to the fragment that is behind it and registers the onClickListener() in the behind fragment rather than the current fragment’s…
0
votes
1 answer

Call method in Fragment / get property from Fragment in FragmentPager

I have one big form broken into 3 fragments. Fragments are contained into FragmentPagerAdapter, so they can be swiped as pages. As there are a lot of calls, I think it wouldn’t be practical to call a interface from the fragment to the activity on…