Fragment switching
/**** fragment switch @params tofragment will switch to the fragment ResId mount fragment the identity of the view Idindex fragment Determine fragment to the left or to the right to use a different animation notes:r.anim.push_left_in, etc. are simple tranlate animation mcurrentfragment for the current fragment, inherited from Basefr agment*/protected void Switchdifffragmentcontent (Fragment tofragment, int resId, int index, Boolean toleft) {if (null = = mcurrentfragment | | NULL = = Tofragment) {return;} if (Mcurrentfragment.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 determine if you have added if (!tofragment.isadded ()) {//hides the current Fragment,add the next fragmentfragmenttrasaction.hide (mcurrentfragment); Fragmenttrasaction.add (ResId, Tofragment, string.valueof (index)); fragmenttransactoin,comMIT ();} else{//hides the current fragment,show the next fragmentfragmenttransaction.hide (mcurrentfragment); Fragmenttransaction.show ( tofragment); Fragmenttransaction.commit ();} Mcurrentfragment = (basefragment) tofragment;} }
Android Common Tool Class package---Fragment