tags:

views:

204

answers:

2

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?

thanks patrick

+1  A: 

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();

This page has some other examples of different types of Dialogs.

Erich Douglass
A: 

in the above answer, just put dismiss() in the public void onClick() function will dismiss the dialog for you.

Yenchi