-2

I have 4 fragments in my viewpager I want to send a call for data every time when my fragment is visible to user. I am using uservisibilityhint() function but it is called only first time in view page and then again it is never called whenever that fragment is visible . is there any way to call it manually every time when the fragment is visible so that I can now that my fragment is visible or not to the user . how can i do this thing

2 Answers 2

0

Use

@Override
public void setUserVisibleHint(boolean visible) {
    super.setUserVisibleHint(visible);
    if (visible && isResumed()) {
        // Your code
    }
}
1
  • i already wrote in my question that this function is called only for first time then it is never called
    – umair_aziz
    Commented Oct 15, 2018 at 7:45
0

Use a Listener on your ViewPager in the Activity like below:

viewPager.setOnPageChangeListener(new OnPageChangeListener...

and here in the listeners callback detect the current View using this method:

ViewPager.getCurrentItem()

and then wire an interface between your activity and four fragments so you can notify which View should try loading fresh data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.