I have an application with a fragments. In one activity there is 3 fragment which is frag1,frag2 and frag3 . It is possible that The OncreateView will trigger is just for frag1 only . In my case frag1 and frag2 are the first to read the onCreateView Event. I just want the frag1 only and when you swipe the frag2 will read and so on.
Asked
Active
Viewed 66 times
0
-
post your code please – Syed Raza Mehdi Jul 22 '15 at 07:50
-
1Are you using a ViewPager? In that case by default, the previous and next fragment will be created – Chol Jul 22 '15 at 07:51
-
`ViewPager.OnPageChangeListener` has method `abstract void onPageSelected(int position)` you can trigger to mark as read or load text when you change page – deadfish Jul 22 '15 at 08:05
-
@Chol Yes. But I want that only one will be created . Is that possible? – ンドリュー ライアンア Jul 22 '15 at 08:15
-
You should use viewPager.setOffScreenPageLimit http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit%28int%29, but I'm not sure you will be able to set it to 0 – Chol Jul 22 '15 at 08:32
1 Answers
0
With the viewPager you are able to set the number of fragment created with the method setOffScreenPageLimit
but unfortunatly I think you will not be able to create only one fragment (the one visible). What will happen when you will slide? As the second fragment is not created, a blank screen...
To be smoothy when scrolling, the second fragment view has to be already created.
Check this response: ViewPager.setOffscreenPageLimit(0) doesn't work as expected
-
Yes, when i scroll to the other one . it will create the one that I will view. and the other will destroy. – ンドリュー ライアンア Jul 23 '15 at 03:06