如何处理关闭RadioButtonDialog
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何处理关闭RadioButtonDialog相关的知识,希望对你有一定的参考价值。
我有这个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();
}
对话电话:
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);
}
}
);
我想处理未点击的事件(点击非对话框或点击取消按钮)。我怎么能这样做?
答案
我找到了解决方案
....
//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();
}
另一答案
只需将侦听器添加到close事件,例如通过setOnDismissListener()
方法。在这个方法中调用某种外层级别的回调也是一个好主意,将这个工作委托给调用者(片段/活动,显示这个对话框),这样你总是会引用当前显示的片段,如果您可能/需要显示多个。
以上是关于如何处理关闭RadioButtonDialog的主要内容,如果未能解决你的问题,请参考以下文章
如何处理已弃用的函数'unarchiveObject(with:)'? [关闭]