```
final String[] choices = { "Item 1", "Item 2", "Item 3"};

final AlertDialog dialog= new AlertDialog.Builder(
    TestSubjectCalendar.this)
    .setTitle("Title")
    .setSingleChoiceItems(choices, pos, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss(); //gives error
            // MORE CODE
        }
    }).create();
    dialog.show();

```

`dialog.dismiss()` is giving the following errors:

> 
> The local variable dialog may not have been initialized
> 
> 
> 

What I want is that when I click an item from the choice list in the `dialog`, the `dialog` should disappear. So how can I go about doing that?

PS: I know I can use `setItems()` instead of `setSingleChoiceItems()`, but I want to use the latter as it provides radio buttons.