Android Common Tool Class package---Fragment

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.