Question

i'm developing a custom DialogPreference.

When user clicks outside the dialog, it is cancelled and i need to avoid this.

I know that Dialog has method setCanceledOnTouchOutside(boolean cancel) that is what i need but the DialogPreference not.

in onBindDialogView i try:

getDialog().setCanceledOnTouchOutside(true);

but getDialog() returns null.

How can i do? Can someone help me?

This is my class:

public class UpdatePreference extends DialogPreference implements View.OnClickListener{


    public UpdatePreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        setPersistent(false);
        setDialogLayoutResource(R.layout.update_dialog_layout);
        setPositiveButtonText("");
        setNegativeButtonText("");
    }

    @Override
    protected void onBindDialogView(View view) {
        super.onBindDialogView(view);   
        //init my components
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        super.onDialogClosed(positiveResult);

    }

}
Was it helpful?

Solution

You can access AlerDialog.Builder before dialog will be shown. There you can specify builder.setCancelable(false). Probably in such way you can achieve desire behavior.

@Override
protected void onPrepareDialogBuilder(Builder builder) {
    super.onPrepareDialogBuilder(builder);
    builder.setCancelable(false);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top