remove Fragment from Activity - Android User Interface

Android examples for User Interface:Fragment

Description

remove Fragment from Activity

Demo Code


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

public class Main {
    public static void removeFragment(Activity activity, int id) {
        FragmentManager fm = activity.getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment fr = fm.findFragmentById(id);

        if (fr != null) {
            ft.remove(fr);//from  w  w w . ja  va2 s  .c om
        }

        ft.commit();
    }
}

Related Tutorials