我正在使用带有 2 个单选按钮的对话框来让用户对对象进行分类。如果用户明确单击其中一个单选按钮,则此方法有效,但如果他们直接按 OK,则无效。我该如何处理这种情况?
case DIALOG_OBJECT_CLASSIFICATION:
return new AlertDialog.Builder(DrawNewPlans.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle("What Object are you drawing?")
.setSingleChoiceItems(R.array.types_of_object, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
makeToast("WhichButton = "+whichButton);
switch (whichButton) {
case 0:
makeToast("User Picked Room");
isRoom = true;
isFurniture = false;
return;
case 1:
makeToast("User Picked Furniture");
isRoom = false;
isFurniture=true;
return;
}
/* User clicked on a radio button do some stuff */
}
})
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
makeToast("classOfRoom is "+classOfRoom);
makeToast("isRoom = "+isRoom);
makeToast("isFurniture = "+isFurniture);
if (isRoom == true && isFurniture == false) {
classOfRoom="Room";
} else if (isRoom == false && isFurniture == true) {
classOfRoom="Furniture";
}
/* User clicked Yes so do some stuff */
isClassified=true;
methodWhichStartsDialogs();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
/* User clicked No so do some stuff */
}
}).create();
}
我刚刚添加了 Toasts 进行调试。非常感谢。