AlertDialog的项目未显示 [英] AlertDialog's items not displayed

查看:75
本文介绍了AlertDialog的项目未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用AlertDialog.Builder创建一个AlertDialog,并用setItems()设置一些项目.显示对话框,但是我看不到任何项目.我所看到的只是消息.

I create an AlertDialog with an AlertDialog.Builder and set some items with setItems(). The dialog is shown but I cannot see any of the items. All I see is the message.

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,则可以看到该按钮.我也尝试设置MultiChoiceItemsSingleChoiceItems,但是这些都不起作用.

If I set the PositiveButton, I can see that button just fine. I also tried setting MultiChoiceItems and SingleChoiceItems but neither of these work either.

推荐答案

使用setTitle而不是setMessage设置邮件正文并覆盖项目列表.

Use setTitle instead of setMessage which sets message body and overrides the items list.

这篇关于AlertDialog的项目未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆