Common Android tool package --- Fragment, android --- fragment

Source: Internet
Author: User

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 ;}}


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.