Android examples for android.support.v4.app:Fragment
replace Fragment
import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import java.util.List; import java.util.Stack; public class Main{ public static void replaceFragment(FragmentManager fragmentManager, int frameId, Fragment fragmentToShow, String fragmentTag, Stack<Fragment> fragmentStack) { if (fragmentToShow == null) { return; }// ww w .java 2 s . c o m List<Fragment> fragmentList = fragmentManager.getFragments(); for (Fragment fragment : fragmentList) { if (fragment == null) { continue; } fragmentManager.beginTransaction().remove(fragment).commit(); if (!fragmentStack.empty()) { fragmentStack.pop(); } } fragmentManager.beginTransaction() .add(frameId, fragmentToShow, fragmentTag).commit(); fragmentStack.push(fragmentToShow); } }