abi
abi

Reputation: 1002

Calling onCreate of next fragment in view pager

while using View pager, I face a strange problem. In my project i have three fragment in a view pager, but while loading the second fragment by swiping from left to right , the OnCreate of third Fragment is automatically calling.in onCreate method i called an Api for getting some data.hence the Api is also called.Normal scenario is like that it only called while loading third fragment by swiping from left to right.

Thanks in Advance

Upvotes: 0

Views: 849

Answers (1)

Rajiv yadav
Rajiv yadav

Reputation: 823

View pager works same as listview. It have same buffer of fragments to increase the UI experience. so it creates fragments in advance and show to he user when asked.

so use http://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html for your purpose.

Thanks

Upvotes: 1

Related Questions