I think that what you are actually asking is "How to get a reference of the ViewPager's Fragment and do something with that".
If this is the case, you can have a look here, you see, its a very common and not that easy problem.
One way to solve ot correctly (providing that you are already using a FragmentStateAdapter) is doing something like the following:
In your activity:
private CustomFragment mHomeFragment;
private CustomFragment mOfferFragment;
private CustomFragment mFavoriteFragment;
private CustomFragment mInfoFragment;
and then, in your adapter
@Override
public Fragment getItem(int position) {
return CustomFragment.newInstance(position, null);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
// save the appropriate reference depending on position
switch (position) {
case 0:
mHomeFragment = (CustomFragment) createdFragment;
break;
case 1:
mOfferFragment = (CustomFragment) createdFragment;
break;
case 2:
mFavoriteFragment = (CustomFragment) createdFragment;
break;
case 3:
mInfoFragment = (CustomFragment) createdFragment;
break;
}
return createdFragment;
}
Doing that, it will allow you to do:
mViewPager.setCurrentItem(1);
mOfferFragment.doSomething();
in your parrent Activity