Cannot get DialogFragment to dismiss programmatically

前端 未结 3 1320
感动是毒
感动是毒 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条回答
  •  Happy的楠姐
    2021-01-14 03:02

    Why not use the methods available on AlertDialog.Builder to build the list, instead of creating your own ListView and populating it?

    I have modified your sample code to show how this would work, and in this example the dialog dismiss() functions fine.

    public Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setSingleChoiceItems(mShareAdapter, 0, new OnClickListener() {
    
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (listener != null) {
                        listener.newShare((ShareType) mShareAdapter.getItem(which));
                    }
                }
            });
            builder.setTitle("Share which?");
            return builder.create();
        }
    

提交回复
热议问题