android - How to avoid reload data when tabs change? -


how can avoid recyclerview reload when tabs change? example, have tablayout 3 tabs, viewpager is:

class viewpageradapter extends fragmentpageradapter {          public viewpageradapter(fragmentmanager fm) {             super(fm);         }          @override         public fragment getitem(int position) {             switch (position) {                 case 0:                     return new tab1fragment();                 case 1:                     return new tab2fragment();                 case 2:                     return new tab3fragment();             }             return null;         }          @override         public int getcount() {             return 3;         }          @override         public charsequence getpagetitle(int position) {             switch (position) {                 case 0:                     return "tab1";                 case 1:                     return "tab2";                 case 2:                     return "tab3";             }             return null;         }      } 

in first one, have recyclerview, when change tabs , first one, list reloaded. there way avoid reload? keep data loaded.

android keeps 1 fragment on either side of current fragment in viewpager default. when come first tab third one, recreate first tab happening in case. here documentation.

you need keep fragments in memory viewpager.setoffscreenpagelimit(<(number of fragments in view pager) - 1>) 2 in case.

of course, docs suggest, number should kept low if complex layout.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo