Stay organized with collections
Save and categorize content based on your preferences.
OnKeyListener
interface OnKeyListener
Interface definition for a callback to be invoked when a key event is dispatched to this dialog. The callback will be invoked before the key event is given to the dialog.
Summary
Public methods |
abstract Boolean |
Called when a key is dispatched to a dialog.
|
Public methods
onKey
abstract fun onKey(
dialog: DialogInterface!,
keyCode: Int,
event: KeyEvent!
): Boolean
Called when a key is dispatched to a dialog. This allows listeners to get a chance to respond before the dialog.
Parameters |
dialog |
DialogInterface!: the dialog the key has been dispatched to |
keyCode |
Int: the code for the physical key that was pressed |
event |
KeyEvent!: the KeyEvent object containing full information about the event |
Return |
Boolean |
true if the listener has consumed the event, false otherwise |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# DialogInterface.OnKeyListener\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nOnKeyListener\n=============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/content/DialogInterface.OnKeyListener \"View this page in Java\") \n\n```\ninterface OnKeyListener\n```\n\n|----------------------------------------------------|\n| [android.content.DialogInterface.OnKeyListener](#) |\n\nInterface definition for a callback to be invoked when a key event is dispatched to this dialog. The callback will be invoked before the key event is given to the dialog.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [onKey](#onKey(android.content.DialogInterface,%20kotlin.Int,%20android.view.KeyEvent))`(`dialog:` `[DialogInterface](/reference/kotlin/android/content/DialogInterface)!`, `keyCode:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `event:` `[KeyEvent](../view/KeyEvent.html#)!`)` Called when a key is dispatched to a dialog. |\n\nPublic methods\n--------------\n\n### onKey\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onKey(\n dialog: DialogInterface!, \n keyCode: Int, \n event: KeyEvent!\n): Boolean\n```\n\nCalled when a key is dispatched to a dialog. This allows listeners to get a chance to respond before the dialog.\n\n| Parameters ||\n|-----------|----------------------------------------------------------------------------------------------------------------------------|\n| `dialog` | [DialogInterface](/reference/kotlin/android/content/DialogInterface)!: the dialog the key has been dispatched to |\n| `keyCode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the code for the physical key that was pressed |\n| `event` | [KeyEvent](../view/KeyEvent.html#)!: the KeyEvent object containing full information about the event |\n\n| Return ||\n|------------------------------------------------------------------------------------|------------------------------------------------------------------|\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true` if the listener has consumed the event, `false` otherwise |"]]