user1324936
user1324936

Reputation: 2187

Android: ViewPager, intercept on fragment load

I have a ViewPager which usually preloads some of its elements. The user can interact with one page which should affects a part of all other elements of the ViewPager.

Currently all my logic is in onCreateView(). I need to get a handle when element is actually shown and change the common part. I tried with onResume() but this function is called earlier. I don't want to redraw the whole element because this is not effective.

Upvotes: 0

Views: 596

Answers (1)

Maulik
Maulik

Reputation: 3316

I am not sure but try using this method:

viewPager.setOffscreenPageLimit(0);

This method will call only one fragment at a time, while you are on that fragment.

Or

Another way is that you can get position of view pager's fragment at run time which is front of screen and according to that particular fragment position you can simply call your method by checking position Like: if(position == 1){}.

Upvotes: 2

Related Questions