Reputation: 133
I have an Activity with a ViewPager
. The ViewPager
includes 3 Fragments
. They can change by a Swipe.
For Example:
My Problems:
OnCreateView
.How can I make that every Fragment call onCreateView
?
onCreateView
of the FirstFragment is called.If I understand the Fragment lifecycle, I think at the moment I switch to the ThirdFragment the FirstFragment is calling the method onDestroyView()
. How can I avoid that, so that everytime each Fragment is 'live'?
I hope you can help me. Please be specific I am a beginner.
BR Marco
Upvotes: 0
Views: 38
Reputation: 7936
Using the Viewpager with FragmentPagerAdapter keeps the fragments in in memory.
When you "load" for first time the fragment, will invoke OnCreate. But the second time Android will look into memory for it, so there is no need to call onCreate agian.
Take a look to the offical documentation: http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
Upvotes: 0