Cannot get DialogFragment to dismiss programmatically

前端 未结 3 1308
感动是毒
感动是毒 2021-01-14 02:34

I have a DialogFragment that shows a list of items to pick from (similar to the attach dialog in Messaging).

My problem is that I cannot get this dialog to dismiss w

3条回答
  •  一向
    一向 (楼主)
    2021-01-14 03:11

    HA....

    I've found it...

    The reason for this is actually ours... we were trying to inflate an xml, and have called:

    DialogFragment.this.getLayoutInflater(null).inflate(...);
    

    This call causes, like I've stated in the comment to create 4 dialogs, and then everything gets messed up.

    The proper way to do this would be to call:

    LayoutInflater layoutInflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layoutInflater.inflate(...);
    

    This fix solved the annoying bug for me on the first go!

提交回复
热议问题