我的应用程序中有一个警报对话框,其中包含自定义标题和标题字段中的复选框,如下所示。
当选择全部复选框时,默认情况下应选中以下所有其他项目(多选列表),如下所示:
此外,如果未选中全部复选框,则之前的选择状态(即选择全部之前) )应勾选,其他项目应取消选择。我希望这一切在对话框聚焦时发生。
我尝试的是下面的代码。
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("title");
View view = getActivity().getLayoutInflater().inflate(
R.layout.dialog_categories_title, null);
cb = (CheckBox) view.findViewById(R.id.checkBox1);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
for (int i = 0; i < _selections.length; i++) {
_selections[i] = isChecked;
}
}
}
});
return new AlertDialog.Builder(getActivity())
.setIcon(R.drawable.alert_dialog_icon)
.setTitle(title)
.setCustomTitle(view)
.setMultiChoiceItems(_categories, _selections,
new DialogSelectionClickHandler())
.setPositiveButton(R.string.alert_dialog_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
((MainActivity) getActivity())
.doPositiveClick();
}
}).create();
}
如果我运行此命令,当选中全部时,仅当我关闭并再次打开对话框时才会检查其他项目,但我希望在当前对话框处于焦点状态。我该怎么做?
最佳答案
CheckBox repeatChkBx = (CheckBox) findViewById(R.id.repeat_checkbox);
repeatChk2 = (CheckBox) findViewById(R.id.repeat_checkbox2);
repeatChkBx.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
repeatChk2.setChecked(true);
}
}
});
关于android - android 中警报对话框自定义标题内的复选框处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13873053/