get Visible Fragment - Android User Interface

Android examples for User Interface:Fragment

Description

get Visible Fragment

Demo Code


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

import java.util.List;

public class Main {
    public static Fragment getVisibleFragment(
            FragmentManager fragmentManager) {
        if (fragmentManager != null) {
            List<Fragment> fragments = fragmentManager.getFragments();
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment != null && fragment.isVisible())
                        return fragment;
                }//from w  ww .  j  a  v  a2s  .  com
            }
        }
        return null;
    }
}

Related Tutorials