# DialogInterface.OnClickListener

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# OnClickListener

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/content/DialogInterface.OnClickListener "View this page in Java")  

```
interface OnClickListener
```

|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [android.content.DialogInterface.OnClickListener](https://developer.android.com/reference/kotlin/android/content/DialogInterface.OnClickListener#) |

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Direct Subclasses [DatePickerDialog](https://developer.android.com/reference/kotlin/android/app/DatePickerDialog.html#),[DialogPreference](https://developer.android.com/reference/kotlin/android/preference/DialogPreference.html#),[Spinner](https://developer.android.com/reference/kotlin/android/widget/Spinner.html#),[TimePickerDialog](https://developer.android.com/reference/kotlin/android/app/TimePickerDialog.html#) |--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------| | [DatePickerDialog](https://developer.android.com/reference/kotlin/android/app/DatePickerDialog.html#)        | A simple dialog containing an[android.widget.DatePicker](https://developer.android.com/reference/kotlin/android/widget/DatePicker.html#).               | | [DialogPreference](https://developer.android.com/reference/kotlin/android/preference/DialogPreference.html#) | A base class for[Preference](https://developer.android.com/reference/kotlin/android/preference/Preference.html#)objects that are dialog-based.          | | [Spinner](https://developer.android.com/reference/kotlin/android/widget/Spinner.html#)                       | A view that displays one child at a time and lets the user pick among them.                                                                             | | [TimePickerDialog](https://developer.android.com/reference/kotlin/android/app/TimePickerDialog.html#)        | A dialog that prompts the user for the time of day using a[TimePicker](https://developer.android.com/reference/kotlin/android/widget/TimePicker.html#). | |

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Indirect Subclasses [EditTextPreference](https://developer.android.com/reference/kotlin/android/preference/EditTextPreference.html#),[ListPreference](https://developer.android.com/reference/kotlin/android/preference/ListPreference.html#),[MultiSelectListPreference](https://developer.android.com/reference/kotlin/android/preference/MultiSelectListPreference.html#) |--------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------| | [EditTextPreference](https://developer.android.com/reference/kotlin/android/preference/EditTextPreference.html#)               | A[Preference](https://developer.android.com/reference/kotlin/android/preference/Preference.html#)that allows for string input.                | | [ListPreference](https://developer.android.com/reference/kotlin/android/preference/ListPreference.html#)                       | A[Preference](https://developer.android.com/reference/kotlin/android/preference/Preference.html#)that displays a list of entries as a dialog. | | [MultiSelectListPreference](https://developer.android.com/reference/kotlin/android/preference/MultiSelectListPreference.html#) | A[Preference](https://developer.android.com/reference/kotlin/android/preference/Preference.html#)that displays a list of entries as a dialog. | |

Interface used to allow the creator of a dialog to run some code when an item on the dialog is clicked.

## Summary

|                                                                                                                                                                                                                                                           Public methods                                                                                                                                                                                                                                                            ||
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onClick](https://developer.android.com/reference/kotlin/android/content/DialogInterface.OnClickListener#onClick(android.content.DialogInterface,%20kotlin.Int))`(`dialog:` `[DialogInterface](https://developer.android.com/reference/kotlin/android/content/DialogInterface)!`, `which:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` This method will be invoked when a button in the dialog is clicked. |

## Public methods

### onClick

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onClick(
    dialog: DialogInterface!, 
    which: Int
): Unit
```

This method will be invoked when a button in the dialog is clicked.

|                                                                                                                                               Parameters                                                                                                                                               ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dialog` | [DialogInterface](https://developer.android.com/reference/kotlin/android/content/DialogInterface)!:the dialog that received the click                                                                                                                                                        |
| `which`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the button that was clicked (ex.[DialogInterface.BUTTON_POSITIVE](https://developer.android.com/reference/kotlin/android/content/DialogInterface#BUTTON_POSITIVE:kotlin.Int)) or the position of the item clicked |