Common Android tool package --- Fragment, android --- fragment
Fragment Switching
/***** Fragment switching @ Params toFragment the Fragment to be switched to the Fragment resId to load the Fragment view Idindex Fragment's identifier indextoleft to determine whether the Fragment switches left or right to use different animated Notes: r. anim. push_left_in is a simple Tranlate animation mCurrentFragment, which is inherited from BaseFragment */protected void switchDiffFragmentContent (Fragment toFragment, int resId, int index, boolean toleft) {if (null = mCurrentFragment | null = toFragment) {return;} if (mCurrentFrag Ment. getArguments (). getInt ("Index ")! = ToFragment. getArguments. getInt ("index") {FragmentTransaction fragmentTransaction; fragmentTrasaction = getChildFragmentManager (). beginTransaction (); if (toleft) {fragmentTrasaction. setCustomAnimations (R. anim. push_left_in, R. anim. push_left_out);} else {fragmentTrasaction. setCustomAnimations (R. anim. push_right_in, R. anim. push_right_out);} // first checks whether the if (! ToFragment. isAdded () {// hide the current fragment, and add the next fragmentfragmentTrasaction. hide (mCurrentFragment); fragmentTrasaction. add (resId, toFragment, String. valueOf (index); fragmentTransactoin, commit ();} else {// hide the current fragment, show the next fragmentfragmentTransaction. hide (mCurrentFragment); fragmentTransaction. show (toFragment); fragmentTransaction. commit ();} mCurrentFragment = (BaseFragment) toFragment ;}}