Remove all fragments from container

前端 未结 9 1599
死守一世寂寞
死守一世寂寞 2021-02-01 00:56

Is there a way to remove all fragments which already added the specific view with its view id?

For example I want to remove all fragments which is added R.id.fragmentcon

9条回答
  •  攒了一身酷
    2021-02-01 01:36

    You can try below code

    getSupportFragmentManager().beginTransaction().remove(frag).commit(); 
    

    *frag is the object of fragment that you want to remove.

     OR
    getFragmentManager().beginTransaction().remove(getFragmentManager().findFragmentById(R.id.your_container)).commit();
    

    it will remove the fragment that is loded in "your_container" container.

    HapPy coding.

提交回复
热议问题