is Showing Same Dialog Fragment - Android User Interface

Android examples for User Interface:Fragment

Description

is Showing Same Dialog Fragment

Demo Code


//package com.java2s;
import android.app.Dialog;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

public class Main {

    public static boolean isShowingSameDialogFragment(
            FragmentManager fragmentManager, String fragmentTag) {

        Fragment prev = fragmentManager.findFragmentByTag(fragmentTag);
        if (prev == null)
            return false;

        if (prev instanceof DialogFragment) {
            final Dialog dialog = ((DialogFragment) prev).getDialog();
            if (dialog != null && dialog.isShowing()) {
                return true;
            }// ww w. j a  v a 2 s.c o  m
        }
        return false;
    }

    public static boolean isShowingSameDialogFragment(
            android.app.FragmentManager fragmentManager, String fragmentTag) {
        android.app.Fragment prev = fragmentManager
                .findFragmentByTag(fragmentTag);
        if (prev == null)
            return false;

        if (prev instanceof android.app.DialogFragment) {
            final Dialog dialog = ((android.app.DialogFragment) prev)
                    .getDialog();
            if (dialog != null && dialog.isShowing()) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials