我创建一个AlertDialog
与AlertDialog.Builder
并设置一些项目进行setItems()
显示该对话框,但我看不到任何项目。 我看到的是消息。
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
dialogBuilder.setMessage("Pick a color");
dialogBuilder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do anything you want here
}
});
dialogBuilder.create().show();
如果我设置PositiveButton
,我可以看到按钮就好了。 我也试着设置MultiChoiceItems
和SingleChoiceItems
但这些都不工作,要么。
使用setTitle
代替setMessage
这台邮件正文和覆盖的项目清单。
Why don't you go for setTitle
instead of the setMessage
? Try with setTitle("Pick a color")
.
I hope it will help you.
尝试alertDialogBuilder.setCustomTitle(view)
使用下面的代码: -
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
dialogBuilder.setTitle("Pick a color");
dialogBuilder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do anything you want here
}
});
dialogBuilder.create().show();
试试这个
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
dialogBuilder.setTitle("Pick a color");
dialogBuilder.setSingleChoiceItems(items,-1, new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
{
}
});
dialogBuilder.show();
如果您正在使用的资源字符串数组必须包括资源的包装。 。上下文()getResources()getStringArray(R.array.items)。
我的列表不是使用R.array.items,直到我给指针的背景和资源的包装展示。
祝好运!