Example usage for android.support.v4.view ViewPager getId

List of usage examples for android.support.v4.view ViewPager getId

Introduction

In this page you can find the example usage for android.support.v4.view ViewPager getId.

Prototype

@IdRes
@ViewDebug.CapturedViewProperty
public int getId() 

Source Link

Document

Returns this view's identifier.

Usage

From source file:Main.java

/**
 * Get a fragment in a {@link ViewPager}s adapter.
 *
 * @param manager/*from   ww  w  .  ja v  a2  s  .  co  m*/
 *     the support fragment manager.
 *     {@link android.support.v4.app.FragmentActivity#getSupportFragmentManager()}
 * @param pager
 *     the {@link ViewPager} holding the {@link android.support.v4.app.Fragment}
 * @param position
 *     the position in the {@link ViewPager} e.g. {@link ViewPager#getCurrentItem()}
 * @param <fragment>
 *     Destination cast class type.
 * @return the fragment at this position in the {@link ViewPager}'s adapter
 */
@SuppressWarnings("unchecked")
public static <fragment extends android.support.v4.app.Fragment> fragment findFragmentByPosition(
        android.support.v4.app.FragmentManager manager, ViewPager pager, int position) {
    return (fragment) manager
            .findFragmentByTag(String.format(Locale.US, FRAGMENT_ADAPTER_ID, pager.getId(), position));
}

From source file:Main.java

/**
 * Get a fragment in a {@link ViewPager}s adapter.
 *
 * @param manager/*from w ww .  j  a v a2s.  c  o  m*/
 *     the support fragment manager {@link android.app.Activity#getFragmentManager()}
 * @param pager
 *     the {@link ViewPager} holding the {@link android.app.Fragment}
 * @param position
 *     the position in the {@link ViewPager} e.g. {@link ViewPager#getCurrentItem()}
 * @param <fragment>
 *     Destination cast class type.
 * @return the fragment at this position in the {@link ViewPager}'s adapter
 */
@SuppressWarnings("unchecked")
public static <fragment extends android.app.Fragment> fragment findFragmentByPosition(
        android.app.FragmentManager manager, ViewPager pager, int position) {
    return (fragment) manager
            .findFragmentByTag(String.format(Locale.US, FRAGMENT_ADAPTER_ID, pager.getId(), position));
}

From source file:com.commonsware.empub.ContentsAdapter.java

Fragment getActiveFragment(ViewPager container, int position) {
    String name = makeFragmentName(container.getId(), position);
    return ctxt.getSupportFragmentManager().findFragmentByTag(name);
}

From source file:com.stepstone.stepper.adapter.AbstractFragmentStepAdapter.java

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public Step findStep(ViewPager viewPager, @IntRange(from = 0) int position) {
    String fragmentTag = "android:switcher:" + viewPager.getId() + ":" + this.getItemId(position);
    return (Step) mFragmentManager.findFragmentByTag(fragmentTag);
}

From source file:org.appd.util.AdapterFragmentTabs.java

/**
 * Make Fragment Name//from  w  w  w  .j a v  a 2 s . c  o m
 * @author Yamel Senih 01/02/2013, 10:20:05
 * @param mViewPager
 * @param index
 * @return
 * @return String
 */
public String makeFragmentName(ViewPager mViewPager, int index) {
    return "android:switcher:" + mViewPager.getId() + ":" + index;
}

From source file:chat.tox.antox.pager.BetterFragmentPagerAdapter.java

/**
 * @return may return null if the fragment has not been instantiated yet for that position - this depends on if the fragment has been viewed
 * yet OR is a sibling covered by { @link android.support.v4.view.ViewPager#setOffscreenPageLimit(int)}. Can use this to call methods on
 * the current positions fragment./*ww  w  . j  a  v  a 2 s .co  m*/
 */

public Fragment getActiveFragment(ViewPager viewPager, int position) {
    String name = BetterFragmentPagerAdapter.makeFragmentName(viewPager.getId(), position);
    return mFragmentManager.findFragmentByTag(name);
}

From source file:com.kenny.openimgur.ui.FragmentPagerAdapter.java

/**
 * @return may return null if the fragment has not been instantiated yet for that position - this depends on if the fragment has been viewed
 * yet OR is a sibling covered by {@link android.support.v4.view.ViewPager#setOffscreenPageLimit(int)}. Can use this to call methods on
 * the current positions fragment.//from   w  w w.j  a  va2s .  c o  m
 */
@Nullable
public Fragment getFragmentForPosition(ViewPager viewPager, FragmentManager fragmentManager, int position) {
    String tag = makeFragmentName(viewPager.getId(), getItemId(position));
    Fragment fragment = fragmentManager.findFragmentByTag(tag);
    return fragment;
}