get Higher Fragment In Stack - Android User Interface

Android examples for User Interface:Fragment

Description

get Higher Fragment In Stack

Demo Code


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

import android.support.v4.app.FragmentManager;

public class Main {
    public static Fragment getHigherFragmentInStack(
            FragmentManager fragmentManager) {

        Fragment currentHigherFragment = null;
        int countFragment = fragmentManager.getBackStackEntryCount();

        if (countFragment > 0) {
            final String tag = fragmentManager.getBackStackEntryAt(
                    countFragment - 1).getName();
            currentHigherFragment = fragmentManager.findFragmentByTag(tag);

            Fragment childFragment = getHigherFragmentInStack(currentHigherFragment
                    .getChildFragmentManager());

            if (childFragment != null) {
                currentHigherFragment = childFragment;
            }/*from  ww  w  .ja  v a  2  s  . c  om*/

        }

        return currentHigherFragment;
    }
}

Related Tutorials