我有checkBox的对话框。在选择这个复选框之前,我想问问用户,他肯定会选择这些复选框。 (我的意思是,我尽量选择复选框,此AlertDialog之前出现,并问我是否相信)AlertDialog在Android中选择checkBox之前
在代码中,它看起来是这样的:
CheckBox cb = (CheckBox) v.findViewById(R.id.favouriteChkBox);
if (cb.isChecked()) {
AlertDialog.Builder builder = new AlertDialog.Builder(
context);
builder.setTitle("Do you want to add this to favourite?");
builder.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
itemChecked.set(position, true);
}
});
builder.setNegativeButton("no",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
builder.create().show();
}
但是,这是行不通的。如果我点击“是”或“否”,则选中复选框,AlertDialog会显示并且不会显示。
你能告诉我为什么这不起作用吗? 谢谢!
你应该复选框的选中状态,当用户点击“否”被设置为false。由于您只是取消alertdialig,所以复选框仍处于检查状态。 – 2013-03-10 04:23:05