Cannot get DialogFragment to dismiss programmatically

前端 未结 3 1330
感动是毒
感动是毒 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:04

    For some - unknown to me - reason, the dialog reference you get back from getDialog() isn't the one you want to work with when inside the listener. You need a reference to the dialog as provided you when you call builder.create();

    For example:

        final AlertDialog dialog = builder.create();
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView parent, View view, int position, long id) {
                dialog.dismiss();
            }
        });
        return dialog;
    

提交回复
热议问题