Get fragment from ViewPager (with FragmentPagerAdapter) by position - Android User Interface

Android examples for User Interface:View Position

Description

Get fragment from ViewPager (with FragmentPagerAdapter) by position

Demo Code


//package com.java2s;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;

public class Main {
    /**/*  w ww  . j a  v a2 s  .  co  m*/
     * Get fragment from ViewPager (with FragmentPagerAdapter) by position
     */
    public static Fragment findFragmentByPosition(FragmentManager fm,
            View viewPager, FragmentPagerAdapter adapter, int position) {
        return fm.findFragmentByTag("android:switcher:" + viewPager.getId()
                + ":" + adapter.getItemId(position));
    }
}

Related Tutorials