DigitsKeyListener

open class DigitsKeyListener : NumberKeyListener
kotlin.Any
   ↳ android.text.method.MetaKeyKeyListener
   ↳ android.text.method.BaseKeyListener
   ↳ android.text.method.NumberKeyListener
   ↳ android.text.method.DigitsKeyListener

For digits-only text entry

As for all implementations of KeyListener, this class is only concerned with hardware keyboards. Software input methods have no obligation to trigger the methods in this class.

Summary

Inherited constants
Public constructors

Use #DigitsKeyListener(Locale) instead.

<init>(sign: Boolean, decimal: Boolean)

Use #DigitsKeyListener(Locale, boolean, boolean) instead.

<init>(locale: Locale?)

<init>(locale: Locale?, sign: Boolean, decimal: Boolean)

Public methods
open CharSequence!
filter(source: CharSequence!, start: Int, end: Int, dest: Spanned!, dstart: Int, dend: Int)

open Int

Returns the input type for the listener.

open static DigitsKeyListener

Returns a DigitsKeyListener that accepts the ASCII digits 0 through 9.

open static DigitsKeyListener
getInstance(sign: Boolean, decimal: Boolean)

Returns a DigitsKeyListener that accepts the ASCII digits 0 through 9, plus the ASCII plus or minus sign (only at the beginning) and/or the ASCII period ('.') as the decimal point (only one per field) if specified.

open static DigitsKeyListener
getInstance(locale: Locale?)

Returns a DigitsKeyListener that accepts the locale-appropriate digits.

open static DigitsKeyListener
getInstance(locale: Locale?, sign: Boolean, decimal: Boolean)

Returns a DigitsKeyListener that accepts the locale-appropriate digits, plus the locale-appropriate plus or minus sign (only at the beginning) and/or the locale-appropriate decimal separator (only one per field) if specified.

open static DigitsKeyListener
getInstance(accepted: String)

Returns a DigitsKeyListener that accepts only the characters that appear in the specified String.

Protected methods
open CharArray

Inherited functions

Public constructors

<init>

DigitsKeyListener()

Deprecated: Use #DigitsKeyListener(Locale) instead.

Allocates a DigitsKeyListener that accepts the ASCII digits 0 through 9.

<init>

DigitsKeyListener(sign: Boolean, decimal: Boolean)

Deprecated: Use #DigitsKeyListener(Locale, boolean, boolean) instead.

Allocates a DigitsKeyListener that accepts the ASCII digits 0 through 9, plus the ASCII plus or minus sign (only at the beginning) and/or the ASCII period ('.') as the decimal point (only one per field) if specified.

<init>

DigitsKeyListener(locale: Locale?)
Parameters
locale Locale?: This value may be null.

<init>

DigitsKeyListener(locale: Locale?, sign: Boolean, decimal: Boolean)
Parameters
locale Locale?: This value may be null.

Public methods

filter

open fun filter(source: CharSequence!, start: Int, end: Int, dest: Spanned!, dstart: Int, dend: Int): CharSequence!

getInputType

added in API level 3
open fun getInputType(): Int

Returns the input type for the listener.
Requires API level 3 (Android 1.5, Cupcake)

getInstance

open static fun getInstance(): DigitsKeyListener

Returns a DigitsKeyListener that accepts the ASCII digits 0 through 9.

Return
DigitsKeyListener: This value will never be null.

getInstance

open static fun getInstance(sign: Boolean, decimal: Boolean): DigitsKeyListener

Returns a DigitsKeyListener that accepts the ASCII digits 0 through 9, plus the ASCII plus or minus sign (only at the beginning) and/or the ASCII period ('.') as the decimal point (only one per field) if specified.

Return
DigitsKeyListener: This value will never be null.

getInstance

added in API level 26
open static fun getInstance(locale: Locale?): DigitsKeyListener

Returns a DigitsKeyListener that accepts the locale-appropriate digits.
Requires API level 26 (Android 8.0, Oreo)

Parameters
locale Locale?: This value may be null.
Return
DigitsKeyListener: This value will never be null.

getInstance

added in API level 26
open static fun getInstance(locale: Locale?, sign: Boolean, decimal: Boolean): DigitsKeyListener

Returns a DigitsKeyListener that accepts the locale-appropriate digits, plus the locale-appropriate plus or minus sign (only at the beginning) and/or the locale-appropriate decimal separator (only one per field) if specified.
Requires API level 26 (Android 8.0, Oreo)

Parameters
locale Locale?: This value may be null.
Return
DigitsKeyListener: This value will never be null.

getInstance

open static fun getInstance(accepted: String): DigitsKeyListener

Returns a DigitsKeyListener that accepts only the characters that appear in the specified String. Note that not all characters may be available on every keyboard.

Parameters
accepted String: This value must never be null.
Return
DigitsKeyListener: This value will never be null.

Protected methods

getAcceptedChars

protected open fun getAcceptedChars(): CharArray