Example usage for android.support.v4.app FragmentManager findFragmentByTag

List of usage examples for android.support.v4.app FragmentManager findFragmentByTag

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager findFragmentByTag.

Prototype

public abstract Fragment findFragmentByTag(String tag);

Source Link

Document

Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction.

Usage

From source file:Main.java

@Nullable
public static Fragment getFragmentByTag(@NonNull FragmentManager fragmentManager, @NonNull String tag) {
    return fragmentManager.findFragmentByTag(tag);
}

From source file:Main.java

public static boolean isFragmentAdded(FragmentManager fragmentManager, Fragment fragment) {
    Fragment fragmentByTag = fragmentManager.findFragmentByTag(fragment.getClass().getSimpleName());
    return !(fragmentByTag == null);
}

From source file:Main.java

public static void startFragment(FragmentManager fm, Fragment fragment, int resId) {
    Fragment mFragment = fm.findFragmentByTag(fragment.getClass().getName());
    FragmentTransaction ft = fm.beginTransaction();
    if (mFragment == null) {
        ft.add(resId, fragment, fragment.getClass().getName());
    }//from  w  w  w  .j a  va 2 s .  c o m
    ft.show(fragment);
    ft.commitAllowingStateLoss();
}

From source file:Main.java

/**
 * Restores the current fragment if it can.
 *
 * @param savedInstanceState//from ww w  .  j  ava2 s. c  o m
 */
public static void restoreFragmentIfPossible(FragmentManager fm, Bundle savedInstanceState, String tag) {
    Fragment fragment = fm.findFragmentByTag(tag);
    if (fragment != null && !fragment.isAdded()) {
        fm.beginTransaction().attach(fragment);
    }
}

From source file:Main.java

public static void hideFragments(FragmentManager fm, String... tags) {
    for (String tag : tags) {
        Fragment fragment = fm.findFragmentByTag(tag);

        if (fragment != null && !fragment.isHidden()) {
            fm.beginTransaction().hide(fragment).commit();
        }/*from www.ja v a  2 s .c o  m*/
    }
}

From source file:at.wada811.app.dialog.ProgressDialogFragment.java

public static ProgressDialogFragment find(FragmentManager fm) {
    return (ProgressDialogFragment) fm.findFragmentByTag(COMMIT_TAG);
}

From source file:ch.berta.fabio.popularmovies.utils.WorkerUtils.java

/**
 * Returns the worker fragment associated with the specified tag.
 *
 * @param fragmentManager the fragment manager to use to find the fragment
 * @param tag             the tag to find the fragment
 * @return the worker fragment associated with the tag
 *//*from  ww  w  . ja v  a2  s. c  om*/
public static Fragment findWorker(@NonNull FragmentManager fragmentManager, @NonNull String tag) {
    return fragmentManager.findFragmentByTag(tag);
}

From source file:com.meiste.greg.ptw.tab.QuestionsLate.java

public static QuestionsLate getInstance(final FragmentManager fm, final String tag) {
    QuestionsLate f = (QuestionsLate) fm.findFragmentByTag(tag);
    if (f == null) {
        f = new QuestionsLate();
    }/*  w  w w  .  j ava  2 s.  com*/
    return f;
}

From source file:com.booksaround.me.title.util.dialog.ProgressDialogFragment.java

public static void hide(FragmentManager manager) {
    DialogFragment dialog = (DialogFragment) manager.findFragmentByTag(ProgressDialogFragment.FRAGMENT_TAG);
    if (dialog == null) {
        return;//from ww  w. ja  v a  2  s .  c  o m
    }
    dialog.dismiss();
}

From source file:com.meiste.greg.ptw.tab.QuestionsConnecting.java

public static QuestionsConnecting getInstance(final FragmentManager fm, final String tag) {
    QuestionsConnecting f = (QuestionsConnecting) fm.findFragmentByTag(tag);
    if (f == null) {
        f = new QuestionsConnecting();
    }//w w w  . java 2 s. c  o m
    return f;
}