Android fragment Hide Show method of call

Source: Internet
Author: User

Loading show hidden fragment in activityImportandroid.app.Activity;ImportAndroid.app.FragmentManager;ImportAndroid.app.FragmentTransaction;ImportAndroid.content.Intent;ImportAndroid.os.Bundle;ImportCom.commons.Config;Importcom.geluyawangluo.withthenight.activitymy.SignInActivity;ImportCom.geluyawangluo.withthenight.fragment.CatFragment;ImportCom.geluyawangluo.withthenight.fragment.ClassificationFragment;ImportCom.geluyawangluo.withthenight.fragment.InformationFragment;ImportCom.geluyawangluo.withthenight.fragment.MyFragment;ImportCom.geluyawangluo.withthenight.fragment.ShoppingFragment;ImportCom.geluyawangluo.withthenight.widget.ScreenManager;ImportCom.geluyawangluo.withthenight.widget.TabBar;Public classMainactivityextendsActivity {PrivateTabBarTabBar;PrivateCatfragmentcatfragment;PrivateClassificationfragmentclassificationfragment;PrivateInformationfragmentinformationfragment;PrivateMyfragmentmyfragment;PrivateShoppingfragmentshoppingfragment;PrivateFragmentmanagerFM;PrivateFragmenttransactionTransaction;PrivateConfigConfig;private intIND=0;@Override    protected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (r.layout.Activity_main);TabBar= (TabBar) Findviewbyid (r.id.TabBar); Screenmanager.getinstance(). Addactivity ( This);Config=config.getinstance();TabBar. AddTab (R.mipmap.Qt1_12, R.mipmap.Qt1_12,"Mall");TabBar. AddTab (R.mipmap.Huodongimage, R.mipmap.Huodongimage,"Activities");TabBar. AddTab (R.mipmap.Shequimage, R.mipmap.Shequimage,"Community");TabBar. AddTab (R.mipmap.qt1_15, R.mipmap.qt1_15,"Shopping Cart");TabBar. AddTab (R.mipmap.qt1_16, R.mipmap.qt1_16,"My");FM=getfragmentmanager ();Transaction=FM. BeginTransaction ();catfragment=NewCatfragment ();classificationfragment=NewClassificationfragment ();myfragment=NewMyfragment ();shoppingfragment=NewShoppingfragment ();informationfragment=NewInformationfragment ();Transaction. Add (r.id.id_content,shoppingfragment);Transaction. Add (r.id.id_content,classificationfragment);Transaction. Add (r.id.id_content,informationfragment);Transaction. Add (r.id.id_content,catfragment);Transaction. Add (r.id.id_content,myfragment). commit ();TabBar. Settabshouldchange (NewTabbar.tabshouldchange () {@Override            Public BooleanShouldchange (intIndex) {// TODO auto-generated Method Stub if(Index = =0) {Getfragmentmanager (). BeginTransaction (). Hide (catfragment). Hide (myfragment). Hide (classificationfragment). Hide (informationfragment). Show (shoppingfragment). commit ();IND=0; }else if(Index = =1) {Getfragmentmanager (). BeginTransaction (). Hide (catfragment). Hide (myfragment). Hide (shoppingfragment). Hide (informationfragment). Show (classificationfragment). commit ();IND=1; }else if(Index = =2) {Getfragmentmanager (). BeginTransaction (). Hide (catfragment). Hide (myfragment). Hide (shoppingfragment). Hide (classificationfragment). Show (informationfragment). commit ();IND=2; }else if(Index = =3) {//Setcatfragment ();                    Getfragmentmanager (). BeginTransaction (). Hide (informationfragment). Hide (myfragment). Hide (shoppingfragment). Hide (classificationfragment). Show (catfragment). commit ();IND=3; }else if(Index = =4) {String land=Config. getString ("UID");if(Land.length () <1) {Intent intent=NewIntent (); Intent.putextra ("Main","Main"); Intent.setclass (mainactivity. This, Signinactivity.class); StartActivity (Intent);TabBar. Setselectedndex (IND);return False; }Else{Getfragmentmanager (). BeginTransaction (). Hide (informationfragment). Hide (catfragment). Hide (shoppingfragment). Hide (classificationfragment). Show (myfragment). commit ();IND=4; }                }return True; }        });//Setshoppingfragment ();        Intent intent= This. Getintent ();if(intent!=NULL) {String Mark=intent.getstringextra ("Mark");if(mark!=NULL&&mark.equals ("Feilei") {Getfragmentmanager (). BeginTransaction (). Hide (catfragment). Hide (myfragment). Hide (shoppingfragment). Hide (informationfragment). Show (classificationfragment). commit ();TabBar. Setselectedndex (1);IND=1; }Else{Getfragmentmanager (). BeginTransaction (). Hide (catfragment). Hide (myfragment). Hide (classificationfragment). Hide (informationfragment). Show (shoppingfragment). commit (); }        }    }}
Fragment display is called when hidden.
The onhiddenchanged method in fragment can update the interface data here .
@Overrideonhiddenchanged (hidden) {    superonhiddenchanged (hidden);}}

Android fragment Hide Show method of call

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.