Reputation: 15744
I have a viewpager that holds 3 different fragments and all fragments has tablelayout which loads dynamicaly. (while saying dynamically, I never try to reach any dataset, I take dataset from bundle already, what I do is just iterate dataset and during this process creating tablerows, textviews and inserting them into tablelayout by one by, so the issue is only creating view as dynamicaly)
My problem is while swiping between fragments it takes a while. I noticed it does that filling operation I mentioned above in oncreateview everytime.
What I want to do is it should create tablelayout just once at the begining and return it everytime as view if fragment would be selected.
When I try that fragments view appears only once and after swiping nothing appears.
I couldnt sleep and I am writing these via my cellphone, so I cant share what I did at the moment but I hope youll get what I want to do and maybe direct me in a good way.
Upvotes: 2
Views: 619
Reputation: 6263
You can use:
myViewPager.setOffscreenPageLimit(3);
which will keep a fragment around once it has been loaded.
Also, you really should use a ListView instead of building out TableRows. This will scroll much smoother and load faster.
Upvotes: 4