how to get a fragment added in an XML layout

前端 未结 5 1487
暗喜
暗喜 2020-12-05 12:27

I have a layout which includes a fragment as follows:



        
5条回答
  •  自闭症患者
    2020-12-05 13:01

    If Fragment is included inside the layout file of Activity then it can be referenced by SupportFragmentManager like...

    MyFragment myFragment= (MyFragment)getSupportFragmentManager().findFragmentById(R.id.FRAGMENTID)
    

    If Fragment is included inside the layout file of another Fragment then it can be referenced by ChildFragmentManager like...

     MyFragment myFragment= (MyFragment)getChildFragmentManager().findFragmentById(R.id.FRAGMENTID)
    

提交回复
热议问题