我想创建一个 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();
从我所查看的例子中,我并没有发现这段代码有什么明显的问题。然而,当我运行它时,它并没有按预期显示供应商对象列表。我还尝试过使用AlertDialog.Builder
的setItems
和setSingleChoiceItems
方法。有谁能看出我错在哪里了吗?