1

I am extending the EditTextPreference class and want to disable one of the default buttons in some situations when showing the dialog.

I got a hint form this answer: EditTextPreference Disable Buttons? about how to access the buttons in the default dialog BUT for some reason getDialog() returns null in all callback methods of the EditTextPreference class.

To be more specific I tried overriding following: onPrepareDialogBuilder(Builder builder) onBindDialogView(View view) onAttachedToActivity() onBindView(View view)

Is it possible at all to affect some of the buttons in the default dialog before showing it (or right after showing it - would work for me too)?

Update: I found a (bit counter-intuitive) solution: just override the showDialog() method of the DialogPreference class like this:

  @Override
  protected void showDialog(Bundle state) {
    super.showDialog(state);
    Dialog dlg = getDialog();
    ...
  }

The getDialog() method returns a non-null value here and you can manipulate the buttons.

Thank you

Vasil

Community
  • 1
  • 1
vap78
  • 1,029
  • 2
  • 11
  • 26

1 Answers1

1

To answer my own question - I found a (bit counter-intuitive) solution: just override the showDialog() method of the DialogPreference class like this:

  @Override
  protected void showDialog(Bundle state) {
    super.showDialog(state);
    Dialog dlg = getDialog();
    ...
  }

The getDialog() method returns a non-null value here and you can manipulate the buttons.

vap78
  • 1,029
  • 2
  • 11
  • 26