Reset/reload fragment container

后端 未结 1 436
-上瘾入骨i
-上瘾入骨i 2020-12-11 12:37

How can I reset or reload a fragment container, to make it empty. I have a master detail view and I want to reset the detail container to empty on a menu item click.This wor

相关标签:
1条回答
  • 2020-12-11 13:15

    Usually you simply remove the fragment from it.

    For example do something like

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

    this will remove the fragment from the your_container holding it.

    This gets the fragment currently present in your_container

    getFragmentManager().findFragmentById(R.id.your_container)
    

    and this remove the fragment

    getFragmentManager().beginTransaction().remove(fragment).commit();
    

    EDIT

    Also sometimes it is useful to ensure all transactions are performed and finished, this can be done by using

    getFragmentManager().executePendingTransactions();
    
    0 讨论(0)
提交回复
热议问题