preference/src/main/java/androidx/preference/PreferenceFragment.java
@Override
    public void onDisplayPreferenceDialog(Preference preference) {

        boolean handled = false;
        if (getCallbackFragment() instanceof OnPreferenceDisplayDialogCallback) {
            handled = ((OnPreferenceDisplayDialogCallback) getCallbackFragment())
                    .onPreferenceDisplayDialog(this, preference);
        }
        if (!handled && getActivity() instanceof OnPreferenceDisplayDialogCallback) {
            handled = ((OnPreferenceDisplayDialogCallback) getActivity())
                    .onPreferenceDisplayDialog(this, preference);
        }

        if (handled) {
            return;
        }

        // check if dialog is already showing
        if (getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
            return;
        }

        final DialogFragment f;
        if (preference instanceof EditTextPreference) {
            f = EditTextPreferenceDialogFragment.newInstance(preference.getKey());
        } else if (preference instanceof ListPreference) {
            f = ListPreferenceDialogFragment.newInstance(preference.getKey());
        } else if (preference instanceof MultiSelectListPreference) {
            f = MultiSelectListPreferenceDialogFragment.newInstance(preference.getKey());
        } else {
            throw new IllegalArgumentException("Tried to display dialog for unknown "
                    + "preference type. Did you forget to override onDisplayPreferenceDialog()?");
        }
        f.setTargetFragment(this, 0);
        f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
    }
/**
     * Called when a preference in the tree requests to display a dialog. Subclasses should
     * override this method to display custom dialogs or to handle dialogs for custom preference
     * classes.
     *
     * @param preference The Preference object requesting the dialog.
     */
Called when a preference in the tree requests to display a dialog. Subclasses should
override this method to display custom dialogs or to handle dialogs for custom preference
classes.

@param preference The Preference object requesting the dialog.
Called when a preference in the tree requests to display a dialog . Subclasses should override this method to display custom dialogs or to handle dialogs for custom preference classes . @param preference The Preference object requesting the dialog .
@Override
    public void onDisplayPreferenceDialog(Preference preference) {
        boolean handled = false;
        if (getCallbackFragment() instanceof OnPreferenceDisplayDialogCallback) {
            handled = ((OnPreferenceDisplayDialogCallback) getCallbackFragment())
                    .onPreferenceDisplayDialog(this, preference);
        }
        if (!handled && getActivity() instanceof OnPreferenceDisplayDialogCallback) {
            handled = ((OnPreferenceDisplayDialogCallback) getActivity())
                    .onPreferenceDisplayDialog(this, preference);
        }
        if (handled) {
            return;
        }
        if (getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
            return;
        }
        final DialogFragment f;
        if (preference instanceof EditTextPreference) {
            f = EditTextPreferenceDialogFragment.newInstance(preference.getKey());
        } else if (preference instanceof ListPreference) {
            f = ListPreferenceDialogFragment.newInstance(preference.getKey());
        } else if (preference instanceof MultiSelectListPreference) {
            f = MultiSelectListPreferenceDialogFragment.newInstance(preference.getKey());
        } else {
            throw new IllegalArgumentException("Tried to display dialog for unknown "
                    + "preference type. Did you forget to override onDisplayPreferenceDialog()?");
        }
        f.setTargetFragment(this, 0);
        f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
    }
@ Override public void onDisplayPreferenceDialog ( Preference preference ) { boolean handled = false ; if ( getCallbackFragment ( ) instanceof OnPreferenceDisplayDialogCallback ) { handled = ( ( OnPreferenceDisplayDialogCallback ) getCallbackFragment ( ) ) . onPreferenceDisplayDialog ( this , preference ) ; } if ( ! handled && getActivity ( ) instanceof OnPreferenceDisplayDialogCallback ) { handled = ( ( OnPreferenceDisplayDialogCallback ) getActivity ( ) ) . onPreferenceDisplayDialog ( this , preference ) ; } if ( handled ) { return ; } if ( getFragmentManager ( ) . findFragmentByTag ( DIALOG_FRAGMENT_TAG ) != null ) { return ; } final DialogFragment f ; if ( preference instanceof EditTextPreference ) { f = EditTextPreferenceDialogFragment . newInstance ( preference . getKey ( ) ) ; } else if ( preference instanceof ListPreference ) { f = ListPreferenceDialogFragment . newInstance ( preference . getKey ( ) ) ; } else if ( preference instanceof MultiSelectListPreference ) { f = MultiSelectListPreferenceDialogFragment . newInstance ( preference . getKey ( ) ) ; } else { throw new IllegalArgumentException ( "Tried to display dialog for unknown " + "preference type. Did you forget to override onDisplayPreferenceDialog()?" ) ; } f . setTargetFragment ( this , 0 ) ; f . show ( getFragmentManager ( ) , DIALOG_FRAGMENT_TAG ) ; }
Called when a preference in the tree requests to display a dialog.
Called when a preference in the tree requests to display a dialog .
// check if dialog is already showing