remove Visible Fragment By Tag - Android User Interface

Android examples for User Interface:Fragment

Description

remove Visible Fragment By Tag

Demo Code


//package com.java2s;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import android.app.Activity;

public class Main {

    public static Boolean removeVisibleFragmentByTag(Context context,
            String tag, int exitTansaction) {
        Fragment fragment = ((Activity) context).getFragmentManager()
                .findFragmentByTag(tag);
        if (fragment != null && fragment.isVisible()) {
            FragmentTransaction ft = ((Activity) context)
                    .getFragmentManager().beginTransaction();
            ft.setCustomAnimations(0, exitTansaction);
            ft.remove(fragment);/* w w w  .j a v  a 2  s  . c  o m*/
            ft.commit();
            return true;
        }
        return false;
    }
}

Related Tutorials