Android examples for Activity:Activity Fragment
replace Fragment From Activity
//package com.java2s; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; public class Main { public static void replaceFragmentFromActivity( @NonNull FragmentManager fragmentManager, @NonNull Fragment oldFragment, @NonNull Fragment newFragment, int frameId, boolean saveToBackStack, String tag) { FragmentTransaction transaction = fragmentManager .beginTransaction();//from w w w. j ava 2 s .co m transaction.remove(oldFragment); transaction.add(frameId, newFragment, tag); if (saveToBackStack) { transaction.addToBackStack(null); } transaction.commit(); } }