Stay organized with collections
Save and categorize content based on your preferences.
DialogInterface.OnKeyListener
public
static
interface
DialogInterface.OnKeyListener
android.content.DialogInterface.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
onKey
public abstract boolean onKey (DialogInterface dialog,
int keyCode,
KeyEvent event)
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 |
Returns |
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](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nDialogInterface.OnKeyListener\n=============================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/content/DialogInterface.OnKeyListener \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\n\n\ninterface\nDialogInterface.OnKeyListener\n`\n\n\n`\n\n\n`\n\n|-----------------------------------------------|\n| android.content.DialogInterface.OnKeyListener |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nInterface definition for a callback to be invoked when a key event is\ndispatched to this dialog. The callback will be invoked before the key\nevent is given to the dialog.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract boolean` | ` `[onKey](/reference/android/content/DialogInterface.OnKeyListener#onKey(android.content.DialogInterface,%20int,%20android.view.KeyEvent))`(`[DialogInterface](/reference/android/content/DialogInterface)` dialog, int keyCode, `[KeyEvent](/reference/android/view/KeyEvent)` event) ` Called when a key is dispatched to a dialog. |\n\nPublic methods\n--------------\n\n### onKey\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract boolean onKey (DialogInterface dialog, \n int keyCode, \n KeyEvent event)\n```\n\nCalled when a key is dispatched to a dialog. This allows listeners to\nget a chance to respond before the dialog.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|------------------------------------------------------------------------------------|\n| `dialog` | `DialogInterface`: the dialog the key has been dispatched to \u003cbr /\u003e |\n| `keyCode` | `int`: the code for the physical key that was pressed \u003cbr /\u003e |\n| `event` | `KeyEvent`: the KeyEvent object containing full information about the event \u003cbr /\u003e |\n\n| Returns ||\n|-----------|-------------------------------------------------------------------------|\n| `boolean` | `true` if the listener has consumed the event, `false` otherwise \u003cbr /\u003e |"]]