Remove all fragments from container

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

    Use this code

    activity?.let {
    it.supportFragmentManager.fragments.forEach { fragment ->
            it.supportFragmentManager.beginTransaction().remove(fragment).commit()
        }
    }
    

    Hope it helps.

    Thank you.

提交回复
热议问题