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

FragmentPagerAdapter with Cursor doesn't recall getItem after swapping the Cursor

I have created FragmentPagerAdapter that uses a Cursor loaded by a Loader. Everytime there's new stuff in the DB the Loader loads the Cursor into the Activity and I swap the Cursor inside the FragmentPagerAdapter and notifyDataSetChanged(). However…
Héctor Júdez Sapena
  • 5,329
  • 3
  • 23
  • 31
0
votes
0 answers

Update partial fragment in viewpager android

I have this problem, in my app there is a viewpager with 3 page, in the middle page (position 1) I have set getPageWidth 0.80f then the page 1 is composed by fragment1 + 0.20 of fragment2 when I scroll to right , from page 0 to page 1 , in this…
bludef
  • 211
  • 2
  • 7
0
votes
2 answers

Force close on orientation change with ViewPager/Fragments/ViewPagerExtensions

I'm having a bit of an issue I can't seem to work around (I haven't worked with fragments in this way before) I have a main FragmentActivity as follows: package com.my.app; import android.app.AlertDialog; import android.content.DialogInterface;…
bbedward
  • 6,368
  • 7
  • 36
  • 59
0
votes
1 answer

Can't change TextView text on event in pager adapter + FragmentPagerAdapter

I have three pages in a FragmentPagerAdapter, and I try to catch the longClick event from a different fragment (not in the pageradapter) and through interfacing use this event to change the text in a textview. It worked to some degree when I saved…
user1545072
0
votes
1 answer

How to add Fragment as view to ViewPager?

I am using viewPager and would like to add fragments to it: public class MyFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup contner, Bundle savedInstanceState) { View view =…
Jani Bela
  • 1,660
  • 4
  • 27
  • 50
0
votes
1 answer

FragmentPagerAdapter class is triggered only when the tab is clicked for the first time

I'm trying to develop a tab based application. Each tab has its fragment. One of them has ViewPager, and ViewPager has its own pages. I move from to another by scrolling in this viewpager. When I open the application for the first time, there is…
essbek
  • 59
  • 1
  • 3
  • 10
0
votes
1 answer

How to change buttons outside PagerView on swipe event

i got an implementation of a FragmentPagerAdapter(this), and i want to change the background of the buttons that are outside of the pager when the fragment change the page. Here's my Main xml
Edgar
  • 467
  • 1
  • 8
  • 23
0
votes
2 answers

FragmentPagerAdapter can't restore listfragment propery

I am developing an Android app made up by 3 fragments; one of them will be a ListFragment, and its content will depend by what happens on the other Fragments. I use a ViewPager object to make the user swype between fragments; this is its adapter…
0
votes
2 answers

How to Use ViewPager to switch to other layout?

public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { Fragment fragment = new…
0
votes
1 answer

Suggested way to retrieve Fragment managed by Adapter

I have fragments in a FragmentActivity, that has an ActionBar and Tab navigation. My problem is that I want to call a method on the Fragment. I cannot use findFragmentBy[Id|Tag], because the fragments are initiated and attached by the adapter, and…
Mate Gulyas
  • 609
  • 2
  • 8
  • 22
0
votes
2 answers

ViewPager + FragmentStatePagerAdapter : need to know when fragment is displayed (selected)

I am using a ViewPager plugged to a FragmentStatePagerAdapter. Each fragment contains a listview. In this listview I wish to display ads and make calls to a analytics server. I only want to make those calls when the user navigates to a fragment (so…
yann.debonnel
  • 766
  • 9
  • 22
0
votes
1 answer

Android, How to know which page of ViewPager has been clicked?

Based on FragmentPagerAdapter, I have inflated my view pager and I can see my items in each page. How to know, which page is clicked by user to direct him/her see detail of information? Thanks
Hesam
  • 52,260
  • 74
  • 224
  • 365
-1
votes
1 answer

i have a dynamic tablayout but every time i push back button and re-enter my app again , my tab doubles , why?

in my TabLayout i create my login TabItem dynamically at the onCreate() method of my MainActivity , but every time i exit from my application with back button and i re-enter my app , it creates that login TabItem again and so it doubles it every…
-1
votes
1 answer

Why is a "Fragment fragment = null" and what is meaning of this definition of fragment?

Here is a piece of code from getItem method of FragmentPagerAdapter: @Override public Fragment getItem(int position) { Fragment fragment = null; switch (position){ case 0: fragment = new…
Dezo
  • 835
  • 9
  • 16
-1
votes
1 answer

Using tabbed for changing fragment and toolbar

I used switch for creating tabbed and Fragment to change pages by tabbed on. now I want to have statement to say if user clicks one for example position 0 like chats Fragment my toolbar changes . what i don't know is that how can i put an if…