Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/text/method/KeyListener#pubmethods)

# KeyListener

*** ** * ** ***

` public interface KeyListener `   
` `

|---|
| android.text.method.KeyListener |

Known indirect subclasses [BaseKeyListener](https://developer.android.com/reference/android/text/method/BaseKeyListener), [DateKeyListener](https://developer.android.com/reference/android/text/method/DateKeyListener), [DateTimeKeyListener](https://developer.android.com/reference/android/text/method/DateTimeKeyListener), [DialerKeyListener](https://developer.android.com/reference/android/text/method/DialerKeyListener), [DigitsKeyListener](https://developer.android.com/reference/android/text/method/DigitsKeyListener), [MultiTapKeyListener](https://developer.android.com/reference/android/text/method/MultiTapKeyListener), [NumberKeyListener](https://developer.android.com/reference/android/text/method/NumberKeyListener), [QwertyKeyListener](https://developer.android.com/reference/android/text/method/QwertyKeyListener), [TextKeyListener](https://developer.android.com/reference/android/text/method/TextKeyListener), [TimeKeyListener](https://developer.android.com/reference/android/text/method/TimeKeyListener) [BaseKeyListener](https://developer.android.com/reference/android/text/method/BaseKeyListener) Abstract base class for key listeners. [DateKeyListener](https://developer.android.com/reference/android/text/method/DateKeyListener) For entering dates in a text field. [DateTimeKeyListener](https://developer.android.com/reference/android/text/method/DateTimeKeyListener) For entering dates and times in the same text field. [DialerKeyListener](https://developer.android.com/reference/android/text/method/DialerKeyListener) For dialing-only text entry

<br />

As for all implementations of `https://developer.android.com/reference/android/text/method/KeyListener`, this class is only concerned with hardware keyboards. [DigitsKeyListener](https://developer.android.com/reference/android/text/method/DigitsKeyListener) For digits-only text entry

<br />

As for all implementations of `https://developer.android.com/reference/android/text/method/KeyListener`, this class is only concerned with hardware keyboards. [MultiTapKeyListener](https://developer.android.com/reference/android/text/method/MultiTapKeyListener) This is the standard key listener for alphabetic input on 12-key keyboards. [NumberKeyListener](https://developer.android.com/reference/android/text/method/NumberKeyListener) For numeric text entry

<br />

As for all implementations of `https://developer.android.com/reference/android/text/method/KeyListener`, this class is only concerned with hardware keyboards. [QwertyKeyListener](https://developer.android.com/reference/android/text/method/QwertyKeyListener) This is the standard key listener for alphabetic input on qwerty keyboards. [TextKeyListener](https://developer.android.com/reference/android/text/method/TextKeyListener) This is the key listener for typing normal text. [TimeKeyListener](https://developer.android.com/reference/android/text/method/TimeKeyListener) For entering times in a text field.   

*** ** * ** ***

Interface for converting text key events into edit operations on an Editable class. Note that for most cases this interface has been superceded by general soft input methods as defined by `https://developer.android.com/reference/android/view/inputmethod/InputMethod`; it should only be used for cases where an application has its own on-screen keypad and also wants to process hard keyboard events to match it.

<br />

Key presses on soft input methods are not required to trigger the methods in this listener, and are in fact discouraged to do so. The default android keyboard will not trigger these for any key to any application targetting Jelly Bean or later, and will only deliver it for some key presses to applications targetting Ice Cream Sandwich or earlier.

<br />

## Summary

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/text/method/KeyListener#clearMetaKeyState(android.view.View,%20android.text.Editable,%20int)(https://developer.android.com/reference/android/view/View view, https://developer.android.com/reference/android/text/Editable content, int states) ` Remove the given shift states from the edited text. |
| ` abstract int` | ` https://developer.android.com/reference/android/text/method/KeyListener#getInputType()() ` Return the type of text that this key listener is manipulating, as per `https://developer.android.com/reference/android/text/InputType`. |
| ` abstract boolean` | ` https://developer.android.com/reference/android/text/method/KeyListener#onKeyDown(android.view.View,%20android.text.Editable,%20int,%20android.view.KeyEvent)(https://developer.android.com/reference/android/view/View view, https://developer.android.com/reference/android/text/Editable text, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` If the key listener wants to handle this key, return true, otherwise return false and the caller (i.e. the widget host) will handle the key. |
| ` abstract boolean` | ` https://developer.android.com/reference/android/text/method/KeyListener#onKeyOther(android.view.View,%20android.text.Editable,%20android.view.KeyEvent)(https://developer.android.com/reference/android/view/View view, https://developer.android.com/reference/android/text/Editable text, https://developer.android.com/reference/android/view/KeyEvent event) ` If the key listener wants to other kinds of key events, return true, otherwise return false and the caller (i.e. the widget host) will handle the key. |
| ` abstract boolean` | ` https://developer.android.com/reference/android/text/method/KeyListener#onKeyUp(android.view.View,%20android.text.Editable,%20int,%20android.view.KeyEvent)(https://developer.android.com/reference/android/view/View view, https://developer.android.com/reference/android/text/Editable text, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` If the key listener wants to handle this key release, return true, otherwise return false and the caller (i.e. the widget host) will handle the key. |

## Public methods

### clearMetaKeyState

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

```
public abstract void clearMetaKeyState (View view, 
                Editable content, 
                int states)
```

Remove the given shift states from the edited text.

<br />

| Parameters ||
|---|---|
| `view` | `View` <br /> |
| `content` | `Editable` <br /> |
| `states` | `int` <br /> |

### getInputType

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

```
public abstract int getInputType ()
```

Return the type of text that this key listener is manipulating, as per `https://developer.android.com/reference/android/text/InputType`. This is used to determine the mode of the soft keyboard that is shown for the editor.

If you return `https://developer.android.com/reference/android/text/InputType#TYPE_NULL` then *no* soft keyboard will provided. In other words, you must be providing your own key pad for on-screen input and the key listener will be used to handle input from a hard keyboard.

If you return any other value, a soft input method will be created when the user puts focus in the editor, which will provide a keypad and also consume hard key events. This means that the key listener will generally not be used, instead the soft input method will take care of managing key input as per the content type returned here.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### onKeyDown

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

```
public abstract boolean onKeyDown (View view, 
                Editable text, 
                int keyCode, 
                KeyEvent event)
```

If the key listener wants to handle this key, return true, otherwise return false and the caller (i.e. the widget host) will handle the key.

<br />

| Parameters ||
|---|---|
| `view` | `View` <br /> |
| `text` | `Editable` <br /> |
| `keyCode` | `int` <br /> |
| `event` | `KeyEvent` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### onKeyOther

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

```
public abstract boolean onKeyOther (View view, 
                Editable text, 
                KeyEvent event)
```

If the key listener wants to other kinds of key events, return true, otherwise return false and the caller (i.e. the widget host) will handle the key.

<br />

| Parameters ||
|---|---|
| `view` | `View` <br /> |
| `text` | `Editable` <br /> |
| `event` | `KeyEvent` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### onKeyUp

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

```
public abstract boolean onKeyUp (View view, 
                Editable text, 
                int keyCode, 
                KeyEvent event)
```

If the key listener wants to handle this key release, return true, otherwise return false and the caller (i.e. the widget host) will handle the key.

<br />

| Parameters ||
|---|---|
| `view` | `View` <br /> |
| `text` | `Editable` <br /> |
| `keyCode` | `int` <br /> |
| `event` | `KeyEvent` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |