VansFannel
VansFannel

Reputation: 45981

ViewPager and Fragments: How can I know when a fragment is not visible?

I'm developing an Android 3.1 Tablet application using android.support.v4.

I want to know if there is an event which is fired when user swipe from one fragment to another one.

Is there an event fired when a fragment is hide by another one?

Upvotes: 0

Views: 836

Answers (1)

user
user

Reputation: 87064

I want to know if there is an event which is fired when user swipe from one fragment to another one.

Is there an event fired when a fragment is hide by another one?

I think what you're looking for is the ViewPager.OnPageChangeListener. You just have to set that listener for your ViewPager to listen for specific events.

From that interface the onPageSelected will tell you(with the int parameter) which page has become the visible one so you know you know which fragment is visible or not.

The onPageScrolled will tell you when the user starts to play with the ViewPager's content.

Upvotes: 1

Related Questions