Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Inherited Constants](https://developer.android.com/reference/android/text/method/DateTimeKeyListener#inhconstants) \| [Fields](https://developer.android.com/reference/android/text/method/DateTimeKeyListener#lfields) \| [Ctors](https://developer.android.com/reference/android/text/method/DateTimeKeyListener#pubctors) \| [Methods](https://developer.android.com/reference/android/text/method/DateTimeKeyListener#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/text/method/DateTimeKeyListener#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/text/method/DateTimeKeyListener#inhmethods)

# DateTimeKeyListener

*** ** * ** ***

` public class DateTimeKeyListener `   
` ` ` ` ` ` ` extends https://developer.android.com/reference/android/text/method/NumberKeyListener ` ` `

|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||||
| ↳ | [android.text.method.MetaKeyKeyListener](https://developer.android.com/reference/android/text/method/MetaKeyKeyListener) ||||
|   | ↳ | [android.text.method.BaseKeyListener](https://developer.android.com/reference/android/text/method/BaseKeyListener) |||
|   |   | ↳ | [android.text.method.NumberKeyListener](https://developer.android.com/reference/android/text/method/NumberKeyListener) ||
|   |   |   | ↳ | android.text.method.DateTimeKeyListener |

<br />

*** ** * ** ***

For entering dates and times in the same text field.

<br />

As for all implementations of `https://developer.android.com/reference/android/text/method/KeyListener`, this class is only concerned with hardware keyboards. Software input methods have no obligation to trigger the methods in this class.

<br />

## Summary

### Inherited constants

From class `https://developer.android.com/reference/android/text/method/MetaKeyKeyListener` `int` `https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#META_ALT_LOCKED`

Flag that indicates that the ALT key is locked.
`int` `https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#META_ALT_ON`

Flag that indicates that the ALT key is on.
`int` `https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#META_CAP_LOCKED`

Flag that indicates that the SHIFT key is locked in CAPS mode.
`int` `https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#META_SHIFT_ON`

Flag that indicates that the SHIFT key is on.
`int` `https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#META_SYM_LOCKED`

Flag that indicates that the SYM key is locked.
`int` `https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#META_SYM_ON`

Flag that indicates that the SYM key is on.

| ### Fields ||
|---|---|
| ` public static final char[]` | `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#CHARACTERS` *This field was deprecated in API level 26. Use `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getAcceptedChars()` instead.* |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/text/method/DateTimeKeyListener#DateTimeKeyListener()() ` *This constructor is deprecated. Use `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#DateTimeKeyListener(java.util.Locale)` instead.* |
| ` https://developer.android.com/reference/android/text/method/DateTimeKeyListener#DateTimeKeyListener(java.util.Locale)(https://developer.android.com/reference/java/util/Locale locale) ` |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getInputType()() ` <br /> |
| ` static https://developer.android.com/reference/android/text/method/DateTimeKeyListener` | ` https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getInstance()() ` *This method was deprecated in API level 26. Use `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getInstance(java.util.Locale)` instead.* |
| ` static https://developer.android.com/reference/android/text/method/DateTimeKeyListener` | ` https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getInstance(java.util.Locale)(https://developer.android.com/reference/java/util/Locale locale) ` Returns an instance of DateTimeKeyListener appropriate for the given locale. |

| ### Protected methods ||
|---|---|
| ` char[]` | ` https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getAcceptedChars()() ` You can say which characters you can accept. |

### Inherited methods

From class ` https://developer.android.com/reference/android/text/method/NumberKeyListener ` ` https://developer.android.com/reference/java/lang/CharSequence` ` https://developer.android.com/reference/android/text/method/NumberKeyListener#filter(java.lang.CharSequence,%20int,%20int,%20android.text.Spanned,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence source, int start, int end, https://developer.android.com/reference/android/text/Spanned dest, int dstart, int dend) `

This method is called when the buffer is going to replace the range `dstart ... dend` of `dest` with the new text from the range `start ... end` of `source`.
` abstract char[]` ` https://developer.android.com/reference/android/text/method/NumberKeyListener#getAcceptedChars()() `

You can say which characters you can accept.
` int` ` https://developer.android.com/reference/android/text/method/NumberKeyListener#lookup(android.view.KeyEvent,%20android.text.Spannable)(https://developer.android.com/reference/android/view/KeyEvent event, https://developer.android.com/reference/android/text/Spannable content) ` ` static boolean` ` https://developer.android.com/reference/android/text/method/NumberKeyListener#ok(char[],%20char)(char[] accept, char c) ` ` boolean` ` https://developer.android.com/reference/android/text/method/NumberKeyListener#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 content, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Handles presses of the meta keys.
From class ` https://developer.android.com/reference/android/text/method/BaseKeyListener ` ` boolean` ` https://developer.android.com/reference/android/text/method/BaseKeyListener#backspace(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 content, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Performs the action that happens when you press the `https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_DEL` key in a `https://developer.android.com/reference/android/widget/TextView`.
` boolean` ` https://developer.android.com/reference/android/text/method/BaseKeyListener#forwardDelete(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 content, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Performs the action that happens when you press the `https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_FORWARD_DEL` key in a `https://developer.android.com/reference/android/widget/TextView`.
` boolean` ` https://developer.android.com/reference/android/text/method/BaseKeyListener#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 content, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Handles presses of the meta keys.
` boolean` ` https://developer.android.com/reference/android/text/method/BaseKeyListener#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 content, https://developer.android.com/reference/android/view/KeyEvent event) `

Base implementation handles ACTION_MULTIPLE KEYCODE_UNKNOWN by inserting the event's text into the content.
From class ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener ` ` static void` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#adjustMetaAfterKeypress(android.text.Spannable)(https://developer.android.com/reference/android/text/Spannable content) `

Call this method after you handle a keypress so that the meta state will be reset to unshifted (if it is not still down) or primed to be reset to unshifted (once it is released).
` static long` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#adjustMetaAfterKeypress(long)(long state) `

Call this method after you handle a keypress so that the meta state will be reset to unshifted (if it is not still down) or primed to be reset to unshifted (once it is released).
` static void` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#clearMetaKeyState(android.text.Editable,%20int)(https://developer.android.com/reference/android/text/Editable content, int states) ` ` long` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#clearMetaKeyState(long,%20int)(long state, int which) `

Clears the state of the specified meta key if it is locked.
` void` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#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) ` ` static final int` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#getMetaState(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence text) `

Gets the state of the meta keys.
` static final int` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#getMetaState(java.lang.CharSequence,%20int)(https://developer.android.com/reference/java/lang/CharSequence text, int meta) `

Gets the state of a particular meta key.
` static final int` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#getMetaState(long)(long state) `

Gets the state of the meta keys.
` static final int` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#getMetaState(java.lang.CharSequence,%20android.view.KeyEvent)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/android/view/KeyEvent event) `

Gets the state of the meta keys for a specific key event.
` static final int` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#getMetaState(long,%20int)(long state, int meta) `

Gets the state of a particular meta key.
` static final int` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#getMetaState(java.lang.CharSequence,%20int,%20android.view.KeyEvent)(https://developer.android.com/reference/java/lang/CharSequence text, int meta, https://developer.android.com/reference/android/view/KeyEvent event) `

Gets the state of a particular meta key to use with a particular key event.
` static long` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#handleKeyDown(long,%20int,%20android.view.KeyEvent)(long state, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Handles presses of the meta keys.
` static long` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#handleKeyUp(long,%20int,%20android.view.KeyEvent)(long state, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Handles release of the meta keys.
` static boolean` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#isMetaTracker(java.lang.CharSequence,%20java.lang.Object)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/java/lang/Object what) `

Returns true if this object is one that this class would use to keep track of any meta state in the specified text.
` static boolean` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#isSelectingMetaTracker(java.lang.CharSequence,%20java.lang.Object)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/java/lang/Object what) `

Returns true if this object is one that this class would use to keep track of the selecting meta state in the specified text.
` boolean` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#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 content, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Handles presses of the meta keys.
` boolean` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#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 content, int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Handles release of the meta keys.
` static long` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#resetLockedMeta(long)(long state) `

Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.
` static void` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#resetLockedMeta(android.text.Spannable)(https://developer.android.com/reference/android/text/Spannable content) `

Call this if you are a method that ignores the locked meta state (arrow keys, for example) and you handle a key.
` static void` ` https://developer.android.com/reference/android/text/method/MetaKeyKeyListener#resetMetaState(android.text.Spannable)(https://developer.android.com/reference/android/text/Spannable text) `

Resets all meta state to inactive.
From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/text/InputFilter ` ` abstract https://developer.android.com/reference/java/lang/CharSequence` ` https://developer.android.com/reference/android/text/InputFilter#filter(java.lang.CharSequence,%20int,%20int,%20android.text.Spanned,%20int,%20int)(https://developer.android.com/reference/java/lang/CharSequence source, int start, int end, https://developer.android.com/reference/android/text/Spanned dest, int dstart, int dend) `

This method is called when the buffer is going to replace the range `dstart ... dend` of `dest` with the new text from the range `start ... end` of `source`.
From interface ` https://developer.android.com/reference/android/text/method/KeyListener ` ` 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.

## Fields

### CHARACTERS

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

```
public static final char[] CHARACTERS
```

<br />

**This field was deprecated in API level 26.**   

Use `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getAcceptedChars()` instead.

This field used to list the characters that were used. But is now a fixed data field that is the list of code units used for the deprecated case where the class is instantiated with null or no input parameter.

<br />

**See also:**

- `https://developer.android.com/reference/android/view/KeyEvent#getMatch(char[])`
- `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getAcceptedChars()`

## Public constructors

### DateTimeKeyListener

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

```
public DateTimeKeyListener ()
```

<br />

**This constructor is deprecated.**   

Use `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#DateTimeKeyListener(java.util.Locale)` instead.

<br />

<br />

### DateTimeKeyListener

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

```
public DateTimeKeyListener (Locale locale)
```

<br />

<br />

| Parameters ||
|---|---|
| `locale` | `Locale`: This value may be `null`. <br /> |

## Public methods

### getInputType

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

```
public int getInputType ()
```

<br />

<br />

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

### getInstance

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

```
public static DateTimeKeyListener getInstance ()
```

<br />

**This method was deprecated in API level 26.**   

Use `https://developer.android.com/reference/android/text/method/DateTimeKeyListener#getInstance(java.util.Locale)` instead.

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/method/DateTimeKeyListener` | This value cannot be `null`. <br /> |

### getInstance

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

```
public static DateTimeKeyListener getInstance (Locale locale)
```

Returns an instance of DateTimeKeyListener appropriate for the given locale.

<br />

| Parameters ||
|---|---|
| `locale` | `Locale`: This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/text/method/DateTimeKeyListener` | This value cannot be `null`. <br /> |

## Protected methods

### getAcceptedChars

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

```
protected char[] getAcceptedChars ()
```

You can say which characters you can accept.

<br />

| Returns ||
|---|---|
| `char[]` | This value cannot be `null`. <br /> |