Remove all fragments from container

前端 未结 9 1766
死守一世寂寞
死守一世寂寞 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:32

    Try this, hope it helps :D

    try {
    if(manager.getFragments()!=null){
        if(manager.getBackStackEntryCount()>0) {
            for (int i = 0; i < manager.getBackStackEntryCount(); i++)
                manager.popBackStack();
    
            manager.beginTransaction().remove(getSupportFragmentManager()
            .findFragmentById(R.id.main_content))
            .commit();
            }
        }
    }catch (Exception e){
        e.printStackTrace();
    } 
    

提交回复
热议问题