In the last two days to do the project, to nest inside the fragment nested fragment, the first use of fragment hide,show and other methods have been unsuccessful,,, the message is a fragment, in which there are two sub-fragment, ( Firends and follow), then the two fragment change Viewpager way to switch, this time must pay attention to msgadapter=new Fragmentmessagepageradapter ( Getchildfragmentmanager ()); In new Pageradapter, be sure to pass in Getchildfragmentmanager() instead of Getsupportfragmentmanager,
The Oncreateview method in the first level fragment:
@Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate ) {mactivity=getactivity (); View View= Inflater.inflate (R.layout.activity_fragment_message,container,false); Button Btnfriends=(Button) View.findviewbyid (r.id.btn_friends); Button Btnfollow=(Button) View.findviewbyid (R.id.btn_follow); Btnfriends.setonclicklistener ( This); Btnfollow.setonclicklistener ( This); VP=(Noscrollviewpager) View.findviewbyid (R.id.vp_noscroll); List_fragments=NewArraylist<fragment>(); //instantiate the two sub-fragment and load it into the collection.Mfrendsfragment=Newmessage_friends_fragment (); List_fragments.add (mfrendsfragment); Mfollowfragment=Newmessage_follow_fragment (); List_fragments.add (mfollowfragment); Msgadapter=NewFragmentmessagepageradapter (Getchildfragmentmanager ()); Vp.setadapter (Msgadapter); returnview; }
Before I wrote, has always been the first to Judge Mfrendsfragment and mfollowfragment and msgadapter not empty I only new, and then do not need to judge whether it is empty, Then I just new the objects, and then I solved the problem (I haven't figured it out yet). It is recommended to switch with Viewpager after fragment
The problem of nesting fragment inside fragment