Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Updating Fragments online in a ViewPager

JoseCarlosToledoMuozJoseCarlosToledoMuoz ESMember ✭✭
edited June 2013 in Xamarin.Android


I am having problems trying to update/replace Fragments in a ViewPager. the problem is that the old fragments simply won't get replaced by the new ones. i have read a couple of solutions on stackoverflow, and tried them, but it still doesn't work.

Project Definition

My goal is create a dinamic catalog. I have a FragmentActivity with a ViewPager. The adapter viewPager class called "Adaptador". The element adapter viewPager is a fragment class called "Fragmento". Each fragment have 2 parameters (rows called "pFilas" and columns called "pColumn") and he create a layouts set Emulating a dinamic grid. I want change rows / columns and viewPager update all fragments online.

I uploaded my project.


Anyone have any ideas why?



  • FZelleFZelle DEMember ✭✭✭

    By using the FragmentPagerAdapter like you do, you create all fragments before the Activity is even shown.

    If you want to change to one of those pages/fragemts you only have to set viewPager.CurrentItem to the number the Frament has you are interested in.

    It would be better to just use a View for the placeholder and change the Fragment in that by using something like:

    Android.Support.V4.App.FragmentTransaction trans = this.SupportFragmentManager.BeginTransaction();
    trans.Replace(Resource.Id.NavigationFragment, fragment);
    if (addToBackstack)
  • JoseCarlosToledoMuozJoseCarlosToledoMuoz ESMember ✭✭
    edited July 2013

    Hello FZelle,

    Do you download my demo project? I would like that you modify my class "fragmento" becouse I dont understand where I must insert your code.

    Example dinamic grid :

    I have 100 elements to show.

    1) I want to show it in fragments with 2x2 grid.


    fragment 1 (4 elements), fragment 2 (4 elements), .....


    TOTAL = 25 fragments to 100 elements.

    2) I want to show it in fragments with 1x2 grid. (I dont get update all fragments).


    fragment 1 (2 elements), fragment 2 (2 elements), .....


    TOTAL = 50 fragments to 100 elements.



  • FZelleFZelle DEMember ✭✭✭

    No, I don't do your work.

    Try to understand what I said.

  • Solved. The problem was that my viewPager adapter was inheriting of "FragmentPagerAdapter" and he must inherits of "FragmentStatePagerAdapter" to update fragments online.


Sign In or Register to comment.