Fragment already added, dialogfragment?

后端 未结 2 1133
温柔的废话
温柔的废话 2021-01-24 10:11

I have a dialogfragment which displays fine but some time when I try to display it I keep getting IllegalStateException

Below is the logcat

         


        
2条回答
  •  长发绾君心
    2021-01-24 10:30

    Here my solution, I have try to click show dialog fragment by tap button multiple time and quickly.

            try{
                FragmentManager fm = getSupportFragmentManager();
                Fragment oldFragment = fm.findFragmentByTag("wait_modal");
    
                if(oldFragment != null && oldFragment.isAdded())
                    return;
    
                if(oldFragment == null && !please_wait_modal.isAdded() && !please_wait_modal.isVisible()){
                    fm.executePendingTransactions();
                    please_wait_modal.show(fm,"wait_modal");
                }
            }catch (Exception e){
                e.printStackTrace();
            }
    

提交回复
热议问题