DialogFragment.getDialog returns null

前端 未结 5 1380
感动是毒
感动是毒 2020-12-02 16:30

I am trying to get the Dialog I have created with an extended DialogFragment using DialogFragment.getDialog() but it returns null.

5条回答
  •  甜味超标
    2020-12-02 17:09

    There is 2 way to show DialogFragment:

      void showDialog() { 
        // Create the fragment and show it as a dialog. 
        DialogFragment newFragment = MyDialogFragment.newInstance(); 
        newFragment.show(getFragmentManager(), "dialog");
    } 
    

    And

     FragmentTransaction ft = getFragmentManager().beginTransaction();
    DialogFragment newFragment = MyDialogFragment.newInstance(); 
    ft.add(R.id.embedded, newFragment);
    ft.commit(); 
    

    You can only get a nonNull dialog when using the first way.

提交回复
热议问题