-1

I'm using this sample to create a simple app, it's made by Joshep Raco (JoeRock11)

https://github.com/JoeRock11/Xamarin_DesignLibrary

I have a problem, I was working with this sample to create a tabbed app, and I found an strange behavior, when the app is starting only the fragment1 and fragment2 loads , but not the fragment3 (when I say load I mean their oncreate and oncreateview method gets triggered ). To load the fragment3 I have to explicity click it, I thought all the fragments would get load but is not the case, don't know why, I would like to know why this happens.

Also, and this is my main problem and I dont know how to fix it, every time I click a fragment tab, I want this fragment to reaload, now seems like it just shows the instantiated fragment on memory, because it doens't triger any method of the fragment, I need to load it again, because I need to refresh its data, now it only reloads randomly. can you or anyone help me solve this please?

Thanks a lot in advance. pd: sorry for my english, it's not my mother language.

1 Answers1

0

I believe this is controlled by the Off Screen Page Limit on the ViewPager control. This value defaults to 1, which basically means, the number of the pages the ViewPager should load at a time is 2, the page that is currently displayed, and the one off screen.

This value can be easily adjusted using the OffscreenPageLimit property on the ViewPager. http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int)


If you want all Fragments to reload data once they are slid on to the screen, you can override UserVisibleHint on each Fragmentand then check to see if the Fragment is visible and execute some code to reload data for that fragment:

public override bool UserVisibleHint {
    get {
            return base.UserVisibleHint;
        }
    set {
          base.UserVisibleHint = value;
          if (value) {
            //Fragment is visible, reload data
          }
    }
}

http://developer.android.com/reference/android/support/v4/app/Fragment.html#setUserVisibleHint(boolean)


Another approach to updating the ViewPager fragments is outlined here: Update ViewPager dynamically?

Community
  • 1
  • 1
pnavk
  • 4,552
  • 2
  • 19
  • 43