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