-2

I can't cancel the click event of the buttons in the background when I open a dialog fragment. I'm trying to call the dialog fragment via a button in another fragment.

public class DialogPaymentSuccessFragment extends DialogFragment {
private View root_view;
class rootViewClick implements OnClickListener {
    rootViewClick () {
    }

    public void onClick(View view) {
        DialogPaymentSuccessFragment.this.dismiss();
    }
}

public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
    this.root_view = layoutInflater.inflate(R.layout.dialog_payment_success, viewGroup, false);
    ((FloatingActionButton) this.root_view.findViewById(R.id.fab)).setOnClickListener(new rootViewClick());
    return this.root_view;
}

@NonNull
public Dialog onCreateDialog(Bundle bundle) {
    bundle = super.onCreateDialog(bundle);
    bundle.requestWindowFeature(1);
    return bundle;
}

public void onDestroyView() {
    super.onDestroyView();
}

}

2 Answers2

0

You can set cancel able false in your onCreateDialog method

like this

this.setCancelable(false)
Arbaz Pirwani
  • 935
  • 7
  • 22
0

If you define rootLayout, you can disable all views in the layout.You can also apply activity before opening the dialogfragment.

public static void enableDisableView(View view, boolean enabled) {
        view.setEnabled(enabled);
        if ( view instanceof ViewGroup) {
            ViewGroup group = (ViewGroup)view;

            for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
                enableDisableView(group.getChildAt(idx), enabled);
            }
        }
    }
Hasan Kucuk
  • 2,433
  • 6
  • 19
  • 41