android - TabLayout: How to load all the tabs or only swipe refresh occur -


i have activity , implement android tablayout recyclerview. implemented 3 fragments 3 tabs of tablayout.

the default load behavior of tablayout load , cache neighbor tab not 1 loaded.

let's fragment a, b , c correspond tab 1, 2 , 3 respectively.

  • when users visit tab 1 ---> fragment , b loaded
  • when users visit tab 2 ---> fragment c loaded
  • but when users visit tab 1 again --> fragment load again.

what want when activity start, want 3 tabs load once, can load tab through refresh mechanism such swipe refresh.

are there way can change load behavior of tablayout?

thanks,

the viewpager default have .setoffscreenpagelimit(1);

this way tab's fragment a, b , c correspond tab 1, 2 , 3 respectively.

when users visit tab 1, fragments , b loaded, c isn't loaded because tabs adjacent tab 1 loaded.

when go tab2, no tab reloaded because adjacent tab2. instead, if go tab 3 tab 1, reloaded.

so must set viewpager.setoffscreenpagelimit(2);

this way tabs loaded once.

but if add more tabs must increase number of setoffscreenpagelimit.


Comments

Popular posts from this blog

multithreading - Exception in Application constructor -

React Native allow user to reorder elements in a scrollview list -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -