Code example for ViewPager

Methods: getAdaptergetCurrentItem

public class ViewPagerUtil { 
    private static final String TAG = "ViewPagerUtil";
    public static Fragment currentFragmentFor(ViewPager viewPager) {
        return (Fragment) viewPager.getAdapter().instantiateItem(viewPager, viewPager.getCurrentItem());
    public static Fragment onSearchRequestedForCurrentFragment(ViewPager viewPager) {
        Fragment fragment = currentFragmentFor(viewPager);
        Log.d(TAG, "want to invoke onSearchRequested for current fragment " + fragment);
        if (fragment instanceof OnSearchRequestedListener) {
            ((OnSearchRequestedListener) fragment).onSearchRequested();
        return fragment;
Experience pair programming with AI  Get Codota for Java