Android examples for User Interface:Fragment
Replace the fragment
import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.util.Log; public class Main{ /**/*w w w .ja v a 2 s.co m*/ * Replace the fragment * * @param context * @param containerId * @param contentFragment */ public static void replace(FragmentActivity context, int containerId, Fragment contentFragment) { FragmentTransaction fragmentTransaction = context .getSupportFragmentManager().beginTransaction(); fragmentTransaction.setCustomAnimations( android.support.design.R.anim.abc_fade_in, android.support.design.R.anim.abc_fade_out); fragmentTransaction.replace(containerId, contentFragment) .commitAllowingStateLoss(); } /** * Replace the fragment * * @param context * @param containerId * @param contentFragment */ public static void replace(FragmentActivity context, int containerId, Fragment contentFragment, int entryAnimation, int exitAnimation) { FragmentTransaction fragmentTransaction = context .getSupportFragmentManager().beginTransaction(); // fragmentTransaction.setCustomAnimations(entryAnimation, exitAnimation, // R.anim.anim_slide_in_right, R.anim.anim_slide_out_right); fragmentTransaction.replace(containerId, contentFragment) .commitAllowingStateLoss(); } }