Removing fragments from an activity

后端 未结 4 1455
陌清茗
陌清茗 2021-01-30 20:54
FragmantClass rSum = new FragmantClass();
getSupportFragmentManager().beginTransaction().remove(rSum).commit();       

I am trying to remove this fragm

4条回答
  •  野性不改
    2021-01-30 21:32

    In my personal case, I add and remove fragment this way:

     if(getSupportFragmentManager().findFragmentById(R.id.container) != null) {
            getSupportFragmentManager()
                    .beginTransaction().
                    remove(getSupportFragmentManager().findFragmentById(R.id.container)).commit();
        }
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.container, fragment)
                .commit();
    

提交回复
热议问题