gpt4 book ai didi

android - 带有 ArrayAdapter 的 AlertDialog 不显示项目列表

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:00 25 4
gpt4 key购买 nike

我想创建一个 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 使用 setItemssetSingleChoiceItems 方法。谁能看到我哪里出错了?

最佳答案

原来你不能同时设置消息和适配器。它在我删除 dialog.setMessage("Message:") 时起作用。

关于android - 带有 ArrayAdapter 的 AlertDialog 不显示项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17950319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com