我还没有能够建立一个单一的选择列表或多重选择列表内的AlertDialog。
I haven't been able to set a Single Choice list, or a Multiple Choice List inside an AlertDialog.
我想下面的例子,但我只得到一个对话框,标题,确定和取消按钮,也没有清单,并且没有信息(这是我定!)。
I tried following the examples but I only get a Dialog with a Title, the Ok and Cancel buttons, and no list, and NO message (which I set!).
下面是code:
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_DELETE_CITY:
CharSequence[] array = {"Red", "Blue", "Yellow"};
return new AlertDialog.Builder(ShowPypData.this)
.setTitle(R.string.city_actions_delete_label)
.setMessage(R.string.city_actions_delete_select_label)
.setSingleChoiceItems(array, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
default:
return null;
}
}
奇怪的是,如果我评论的setSingleChoiceItems部分,我可以看到该消息的对话框。
The weird thing is that if I comment the setSingleChoiceItems part, I can see the message on the dialog.
看来,按钮,消息和多选择的项目是相互排斥的。试评出来setMessage,setPositiveButton和setNegativeButton。没有检查它自己。
Seems that Buttons, Message and Multiple choice items are mutually exclusive. Try to comment out setMessage, setPositiveButton and setNegativeButton. Didn't check it myself.