Android - Start Fragemnt from another Fragment C#

后端 未结 3 1183
长情又很酷
长情又很酷 2021-01-28 00:20

I know this question has been asked too much here but i ahve tried every solution out there to open a fragment from another fragment and no one worked for me.

Fr

3条回答
  •  情歌与酒
    2021-01-28 01:17

    You need a FrameLayout to contain your LinearLayout:

    
    
      
    
    
        
        
        

    And your code should be :

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            var view = inflater.Inflate(Resource.Layout.my_layout, container, false);
            var ll = view.FindViewById(Resource.Id.ll);
            var bt = view.FindViewById(Resource.Id.addbtn);
            bt.Click+= delegate
            {
                Fragment2 fragment2 = new Fragment2();
                FragmentTransaction ft = FragmentManager.BeginTransaction();
                ft.Replace(Resource.Id.content_frame, fragment2);
                ft.Commit();
                ll.Visibility = ViewStates.Gone;
            };
            return view;
        }
    

    You can refer to this to see why your fragment2 just top on it. I use ll.Visibility = ViewStates.Gone; to avoid it.

提交回复
热议问题