Skip to content

Most visited

Recently visited

navigation

DigitsKeyListener

public class DigitsKeyListener
extends NumberKeyListener

java.lang.Object
   ↳ 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

From class android.text.method.MetaKeyKeyListener

Public constructors

DigitsKeyListener()

This constructor was deprecated in API level O. Use DigitsKeyListener(Locale) instead.

DigitsKeyListener(boolean sign, boolean decimal)

This constructor was deprecated in API level O. Use DigitsKeyListener(Locale, boolean, boolean) instead.

DigitsKeyListener(Locale locale)
DigitsKeyListener(Locale locale, boolean sign, boolean decimal)

Public methods

CharSequence filter(CharSequence source, int start, int end, 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.

int getInputType()
static DigitsKeyListener getInstance(String accepted)

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

static DigitsKeyListener getInstance()

This method was deprecated in API level O. Use getInstance(Locale) instead.

static DigitsKeyListener getInstance(Locale locale)

Returns a DigitsKeyListener that accepts the locale-appropriate digits.

static DigitsKeyListener getInstance(Locale locale, boolean sign, boolean decimal)

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.

static DigitsKeyListener getInstance(boolean sign, boolean decimal)

This method was deprecated in API level O. Use getInstance(Locale, boolean, boolean) instead.

Protected methods

char[] getAcceptedChars()

You can say which characters you can accept.

Inherited methods

From class android.text.method.NumberKeyListener
From class android.text.method.BaseKeyListener
From class android.text.method.MetaKeyKeyListener
From class java.lang.Object
From interface android.text.InputFilter
From interface android.text.method.KeyListener

Public constructors

DigitsKeyListener

added in API level 1
DigitsKeyListener ()

This constructor was deprecated in API level O.
Use DigitsKeyListener(Locale) instead.

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

DigitsKeyListener

added in API level 1
DigitsKeyListener (boolean sign, 
                boolean decimal)

This constructor was deprecated in API level O.
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.

Parameters
sign boolean
decimal boolean

DigitsKeyListener

DigitsKeyListener (Locale locale)

Parameters
locale Locale

DigitsKeyListener

DigitsKeyListener (Locale locale, 
                boolean sign, 
                boolean decimal)

Parameters
locale Locale
sign boolean
decimal boolean

Public methods

filter

added in API level 1
CharSequence filter (CharSequence source, 
                int start, 
                int end, 
                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. Return the CharSequence that you would like to have placed there instead, including an empty string if appropriate, or null to accept the original replacement. Be careful to not to reject 0-length replacements, as this is what happens when you delete text. Also beware that you should not attempt to make any changes to dest from this method; you may only examine it for context. Note: If source is an instance of Spanned or Spannable, the span objects in the source should be copied into the filtered result (i.e. the non-null return value). copySpansFrom(Spanned, int, int, Class, Spannable, int) can be used for convenience.

Parameters
source CharSequence
start int
end int
dest Spanned
dstart int
dend int
Returns
CharSequence

getInputType

added in API level 3
int getInputType ()

Returns
int

getInstance

added in API level 1
DigitsKeyListener getInstance (String accepted)

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
Returns
DigitsKeyListener

getInstance

added in API level 1
DigitsKeyListener getInstance ()

This method was deprecated in API level O.
Use getInstance(Locale) instead.

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

Returns
DigitsKeyListener

getInstance

DigitsKeyListener getInstance (Locale locale)

Returns a DigitsKeyListener that accepts the locale-appropriate digits.

Parameters
locale Locale
Returns
DigitsKeyListener

getInstance

DigitsKeyListener getInstance (Locale locale, 
                boolean sign, 
                boolean decimal)

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.

Parameters
locale Locale
sign boolean
decimal boolean
Returns
DigitsKeyListener

getInstance

added in API level 1
DigitsKeyListener getInstance (boolean sign, 
                boolean decimal)

This method was deprecated in API level O.
Use getInstance(Locale, boolean, boolean) instead.

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.

Parameters
sign boolean
decimal boolean
Returns
DigitsKeyListener

Protected methods

getAcceptedChars

added in API level 1
char[] getAcceptedChars ()

You can say which characters you can accept.

Returns
char[]
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.