【发布时间】:2012-10-17 14:43:04
【问题描述】:
我正在使用以下代码创建一个对话框,其中包含来自 studentNames ArrayList 的列表项。我通过读取 childfile 数组来创建此 ArrayList。但是当此代码运行时,它只显示一个带有零列表项的对话框。我什至有检查我的 studentNames 是否为 null,但其中包含值。根据文档,我需要设置 ListAdapter 以在 Dialog box 中显示列表项,但这对我也不起作用。请帮我找出问题。
ArrayList<String> studentNames = new ArrayList<String>();
for (File file2 : childfile) {
studentNames.add(file2.getName());
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(student.getName()).setAdapter(new ArrayAdapter(context, android.R.layout.simple_list_item_1, studentNames),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
cases
}
}
});
builder.create();
builder.show();
【问题讨论】:
-
你忘记了 setItems
标签: android android-listview android-dialog android-adapter