Disable touch events on base views while DialogFragment is displayed

I have a PreferenceFragment, and while I'm configuring everything I need, I'm showing the progress of loading the DialogFragment signature. The problem is, if I click on the preference items in the base fragment, click events are still being processed.

Is there a way to disable events while the DialogFragment is displayed?

My DialogFragment is created and run from the PreferenceFragment itself:

 final DialogFragment fragment = new DialogFragment() {
                @Override
                public Dialog onCreateDialog(final Bundle savedInstanceState) {
                    final Dialog dialog = new AlertDialog.Builder(getActivity())
                            .setTitle(R.string.dialog_hide_user_title)
                            .setMessage(R.string.dialog_hide_user_summary)
                            .setPositiveButton(R.string.dialog_hide_user_confirm_button, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(final DialogInterface dialogInterface, final int i) {
                                    callback.onPositiveClick();
                                }
                            })
                            .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(final DialogInterface dialogInterface, final int i) {
                                    callback.onNegativeClick();
                                }
                            })
                            .create();
                    dialog.setCanceledOnTouchOutside(false);
                    return dialog;
                }
            };
fragment.show(getFragmentManager(), "test");

      

+3


source to share


3 answers


Try

setCancelable(false);
dialog.setCanceledOnTouchOutside(false);

      

Hope it helps :)



Complete code:

final DialogFragment fragment = new DialogFragment() {
                @Override
                public Dialog onCreateDialog(final Bundle savedInstanceState) {
                    final Dialog dialog = new AlertDialog.Builder(getActivity())
                            .setTitle(R.string.dialog_hide_user_title)
                            .setMessage(R.string.dialog_hide_user_summary)
                            .setPositiveButton(R.string.dialog_hide_user_confirm_button, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(final DialogInterface dialogInterface, final int i) {
                                    callback.onPositiveClick();
                                }
                            })
                            .setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(final DialogInterface dialogInterface, final int i) {
                                    callback.onNegativeClick();
                                }
                            })
                            .create();
                    setCancelable(false);
                    dialog.setCanceledOnTouchOutside(false);
                    return dialog;
                }
            };
fragment.show(getFragmentManager(), "test");

      

+3


source


You just need to customize your base layout view:



android:clickable="true"

      

+1


source


I wrote this in my main activity and it worked

 private void myDy() {
     FragmentManager manager = getSupportFragmentManager();
     TimerDialogFrag dialog = new TimerDialogFrag();
      dialog.setCancelable(false);
     dialog.show(manager, DIALOG_DATE);
}

      

0


source







All Articles