带有ArrayAdapter的AlertDialog未显示项目列表

Stu*_*son 4 android android-alertdialog

我想创建一个AlertDialog显示自定义对象列表Supplier.toString()已重写该方法以显示说明.

AlertDialog.Builder dialog = new AlertDialog.Builder(ExampleActivity.this);
dialog.setTitle("Title");
dialog.setMessage("Message:");

final ArrayAdapter<Supplier> adapter = new ArrayAdapter<Supplier>(
        ExampleActivity.this, android.R.layout.select_dialog_singlechoice);

adapter.add(new Supplier());
adapter.add(new Supplier());
adapter.add(new Supplier());

dialog.setAdapter(adapter, new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {

    }
});
dialog.setNegativeButton("Cancel", null);
dialog.show();
Run Code Online (Sandbox Code Playgroud)

从我看过的例子中,我发现这段代码没有明显错误.但是,当我运行它时,它不会按预期显示供应商对象的列表.我也尝试过使用setItemssetSingleChoiceItems方法AlertDialog.Builder.任何人都可以看到我错在哪里?

Stu*_*son 9

事实证明,您无法一起设置消息和适配器.我删除时它可以工作dialog.setMessage("Message:").