@Override
    public void setPrimaryItem(final ViewGroup container, final int position,
        final Object object) {
        super.setPrimaryItem(container, position, object);

        boolean changed = false;
        if (object instanceof Fragment) {
            changed = object != selected;
            selected = (Fragment) object;
        } else {
            changed = object != null;
            selected = null;
        }

        if (changed) {
            activity.invalidateOptionsMenu();
        }
    }
This method is used to get a reference to created fragments in the adapter.

@param fragmentPosition
position of the fragment in the pager.

@return corresponding fragment that is created
during {@link #instantiateItem(ViewGroup, int)}
app/src/main/java/com/github/pockethub/android/ui/base/FragmentPagerAdapter.java