不显示AlertDialog的项目(AlertDialog's items not disp

2019-07-29 12:40发布

我创建一个AlertDialogAlertDialog.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 ,我可以看到按钮就好了。 我也试着设置MultiChoiceItemsSingleChoiceItems但这些都不工作,要么。

Answer 1:

使用setTitle代替setMessage这台邮件正文和覆盖的项目清单。



Answer 2:

Why don't you go for setTitle instead of the setMessage? Try with setTitle("Pick a color").

I hope it will help you.



Answer 3:

尝试alertDialogBuilder.setCustomTitle(view)



Answer 4:

使用下面的代码: -

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();


Answer 5:

试试这个

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();


Answer 6:

如果您正在使用的资源字符串数组必须包括资源的包装。 。上下文()getResources()getStringArray(R.array.items)。

我的列表不是使用R.array.items,直到我给指针的背景和资源的包装展示。

祝好运!



文章来源: AlertDialog's items not displayed