The problem of nesting fragment inside fragment

Source: Internet
Author: User

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

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.