Ad

How To Handle Close RadioButtonDialog

I have this RadioPickerDialog:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialog_radio_buttons, null);
    ButterKnife.bind(this, view);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    TextView tvTitle = view.findViewById(R.id.dialog_radio_title);
    tvTitle.setText(title);
    builder.setView(view)
            .setPositiveButton(R.string.btn_ok, (DialogInterface.OnClickListener) (dialog, which) -> {
                listener.onPickerConfirmClicked(getSelectedIndex());
                dialog.dismiss();
            })
            .setNegativeButton(R.string.btn_cancel, (DialogInterface.OnClickListener) (dialog, which) -> {
                dialog.dismiss();
            });

    for (int i = 0; i < items.size(); i++) {
        RadioButton radioButton = new RadioButton(getActivity());
        T item = items.get(i);
        radioButton.setText(item.toString());
        radioGroup.addView(radioButton);
    }

    RadioButton buttonCheckedByDefault = (RadioButton) radioGroup.getChildAt(defItemNum);
    buttonCheckedByDefault.setChecked(true);
    return builder.create();
}

Dialog call:

UiUtils.showRadioButtonPickerDialog(this, reasonList, getString(R.string.workshift_pause), 0, new RadioButtonPickerDialog.PickerListener() {
                @Override
                public void onPickerConfirmClicked(int selectedIndex) {
                    presenter.setPause(reasonList.get(selectedIndex), true);
                }
            }
    );

I want to handle not clicked event (click in not dialog or click on cancel button). How i can do it?

Ad

Answer

i found solution:

....
//When clicked negativeButton
@Override
public void onCancel(DialogInterface dialog){
    dialog.dismiss();
}

//when clicked not in the dialog box
@Override
public void onDismiss(DialogInterface dialog){
    dialog.dismiss();
}
Ad
source: stackoverflow.com
Ad