AlertDialog:为什么我不能同时显示Message和List? [英] AlertDialog: Why can't I show Message and List together?
本文介绍了AlertDialog:为什么我不能同时显示Message和List?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道为什么当我添加带有.setMessage()
的消息时AlertDialog
不显示项目列表吗?
将会显示负号和正号按钮,但不会显示列表.
当我用.setMessage()
删除行时,一切正常.
Does anybody know why the AlertDialog
doesn't show the list of items when I add a Message with .setMessage()
?
The negative and positive buttons will be shown, but not the list.
When I delete the line with .setMessage()
everything works.
这是我的代码:
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this.getActivity());
myAlertDialog.setTitle("Options");
myAlertDialog.setMessage("Choose a color.");
CharSequence[] items = {"RED", "BLUE", "GREEN" };
myAlertDialog.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do stuff
}
});
myAlertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do stuff
}
});
myAlertDialog.setPositiveButton("YES",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do stuff
}
});
myAlertDialog.create();
myAlertDialog.show();
推荐答案
来自文档,
由于该列表显示在对话框的内容区域中,因此该对话框无法同时显示消息和列表,因此您应该使用setTitle()设置对话框的标题.
Because the list appears in the dialog's content area, the dialog cannot show both a message and a list and you should set a title for the dialog with setTitle().
因此setMessage()
和setSingleChoiceItems()
是互斥的.
这篇关于AlertDialog:为什么我不能同时显示Message和List?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文