How to implement a ViewPager with different Fragments / Layouts

When I start an activity which implements viewpager, the viewpager created various fragments. I want to use different layouts for each fragment, but the problem is that viewpager shows only two layouts at the max (second layout on all of the remaining fragments after 1). Here is the code for SwipeActivity which implements the viewpager … Read more

Replace Fragment inside a ViewPager

I’m trying to use Fragment with a ViewPager using the FragmentPagerAdapter. What I’m looking for to achieve is to replace a fragment, positioned on the first page of the ViewPager, with another one. The pager is composed of two pages. The first one is the FirstPagerFragment, the second one is the SecondPagerFragment. Clicking on a … Read more

Update ViewPager dynamically?

I can’t update the content in ViewPager. What is the correct usage of methods instantiateItem() and getItem() in FragmentPagerAdapter class? I was using only getItem() to instantiate and return my fragments: @Override public Fragment getItem(int position) { return new MyFragment(context, paramters); } This worked well. Except I can’t change the content. So I found this: … Read more

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter? About FragmentPagerAdapter Google’s guide says: 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, … Read more

ViewPager and fragments — what’s the right way to store fragment’s state?

Fragments seem to be very nice for separation of UI logic into some modules. But along with ViewPager its lifecycle is still misty to me. So Guru thoughts are badly needed! Edit See dumb solution below 😉 Scope Main activity has a ViewPager with fragments. Those fragments could implement a little bit different logic for … Read more