我在 AlertDialog 中使用 ListView 来显示项目列表。当用户单击其中一项时,我希望关闭对话框。我不会在对话框上有任何操作按钮。关于我将如何实现这一点的任何想法?
最佳答案
您应该能够执行以下操作:
final CharSequence[] items = {"Foo", "Bar", "Baz"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Make your selection");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Do something with the selection
}
});
AlertDialog alert = builder.create();
alert.show();
这个 page还有一些不同类型对话框的其他示例。
关于android - 警报对话框中的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2397106/