public class DigitsKeyListener extends NumberKeyListener
KeyListener
, this class is only concerned
with hardware keyboards. Software input methods have no obligation to trigger
the methods in this class.InputFilter.AllCaps, InputFilter.LengthFilter
META_ALT_LOCKED, META_ALT_ON, META_CAP_LOCKED, META_SELECTING, META_SHIFT_ON, META_SYM_LOCKED, META_SYM_ON
Constructor and Description |
---|
DigitsKeyListener()
Allocates a DigitsKeyListener that accepts the digits 0 through 9.
|
DigitsKeyListener(boolean sign,
boolean decimal)
Allocates a DigitsKeyListener that accepts the digits 0 through 9,
plus the minus sign (only at the beginning) and/or decimal point
(only one per field) if specified.
|
Modifier and Type | Method and Description |
---|---|
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 . |
protected char[] |
getAcceptedChars()
You can say which characters you can accept.
|
int |
getInputType()
Return the type of text that this key listener is manipulating,
as per
InputType . |
static DigitsKeyListener |
getInstance()
Returns a DigitsKeyListener that accepts the digits 0 through 9.
|
static DigitsKeyListener |
getInstance(boolean sign,
boolean decimal)
Returns a DigitsKeyListener that accepts the digits 0 through 9,
plus the minus sign (only at the beginning) and/or decimal point
(only one per field) if specified.
|
static DigitsKeyListener |
getInstance(String accepted)
Returns a DigitsKeyListener that accepts only the characters
that appear in the specified String.
|
lookup, ok, onKeyDown
backspace, forwardDelete, onKeyOther
adjustMetaAfterKeypress, adjustMetaAfterKeypress, clearMetaKeyState, clearMetaKeyState, clearMetaKeyState, getMetaState, getMetaState, getMetaState, getMetaState, handleKeyDown, handleKeyUp, isMetaTracker, isSelectingMetaTracker, onKeyUp, resetLockedMeta, resetLockedMeta, resetMetaState, startSelecting, stopSelecting
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clearMetaKeyState, onKeyUp
public DigitsKeyListener()
public DigitsKeyListener(boolean sign, boolean decimal)
protected char[] getAcceptedChars()
NumberKeyListener
getAcceptedChars
in class NumberKeyListener
public static DigitsKeyListener getInstance()
public static DigitsKeyListener getInstance(boolean sign, boolean decimal)
public static DigitsKeyListener getInstance(String accepted)
public int getInputType()
KeyListener
InputType
. This is used to
determine the mode of the soft keyboard that is shown for the editor.
If you return
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.
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
InputFilter
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).
TextUtils.copySpansFrom(android.text.Spanned, int, int, java.lang.Class, android.text.Spannable, int)
can be used for convenience.filter
in interface InputFilter
filter
in class NumberKeyListener