我正在使用的AlertDialog一个ListView显示的项目清单。当用户点击的项目之一,我想对话框关闭。我也不会在对话框上的任何操作按钮。如何我会做到这一点任何想法?
I am using a ListView in an AlertDialog to display a list of items. When the user clicks on one of the items, I want the dialog to close. I would not have any action buttons on the dialog. Any ideas on how I would accomplish this?
您应该能够做这样的事情:
You should be able to do something like:
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();
此页面有不同类型对话框中的其他一些例子。
This page has some other examples of different types of Dialogs.