net.rim.device.api.ui.text
Class NumericTextFilter

java.lang.Object
  extended by net.rim.device.api.ui.text.TextFilter
      extended by net.rim.device.api.ui.text.NumericTextFilter

public class NumericTextFilter
extends TextFilter

Filters out characters not usable in strings showing numeric data.

This filter favours characters in numeric strings (that is numeric digits, and a minus sign if in the first position.


Field Summary
static int ALLOW_DECIMAL
          Text style that allows numeric strings with decimal notation.
static int ALLOW_NEGATIVE
          Text style that allows negative numbers in numeric strings.
 
Fields inherited from class net.rim.device.api.ui.text.TextFilter
ADN_SIM_PHONE, DEFAULT, DEFAULT_SMART_PHONE, EMAIL, FDN_SIM_PHONE, FILENAME, HEXADECIMAL, INTEGER, IP, LOWERCASE, NUMERIC, PHONE, PIN_ADDRESS, REAL_NUMERIC, SIM_PHONE, SMS_PHONE, STYLE_SHIFT, UPPERCASE, URL, VOICEMAIL_PHONE
 
Constructor Summary
NumericTextFilter()
          Constructs a new NumericTextFilter instance.
NumericTextFilter(int style)
          Constructs a new NumericTextFilter instance with provided style.
 
Method Summary
 char convert(char character, int status)
          Passes character through numeric text filter.
 char convert(char character, AbstractString text, int position, int status)
          Passes character through numeric text filter.
 boolean validate(char character)
          Determines if character is valid numeric string character.
 boolean validate(char character, AbstractString text, int position)
          Determines if character is valid numeric string character.
 boolean validate(AbstractString text)
          Determines if provided string contains valid numeric characters.
 
Methods inherited from class net.rim.device.api.ui.text.TextFilter
get
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Field Detail

ALLOW_NEGATIVE

public static final int ALLOW_NEGATIVE
Text style that allows negative numbers in numeric strings.

See Also:
Constant Field Values

ALLOW_DECIMAL

public static final int ALLOW_DECIMAL
Text style that allows numeric strings with decimal notation.

See Also:
Constant Field Values


Constructor Detail

NumericTextFilter

public NumericTextFilter()
Constructs a new NumericTextFilter instance.

This method builds a new numeric text filter that allows neither negative integers, nor decimals.


NumericTextFilter

public NumericTextFilter(int style)
Constructs a new NumericTextFilter instance with provided style.

Use this method to build a new numeric text filter that can allow negative numbers and/or decimals.

Parameters:
style - Style for this field.


Method Detail

convert

public char convert(char character,
                    int status)
Passes character through numeric text filter.

Specified by:
convert in class TextFilter
Parameters:
character - Character to test.
status - Ignored.
Returns:
If you provide a valid character, this method passes it through unaltered. Otherwise, this method returns the ALTed version of the provided character or \u0000.

convert

public char convert(char character,
                    AbstractString text,
                    int position,
                    int status)
Passes character through numeric text filter.

Overrides:
convert in class TextFilter
Parameters:
character - Character to test.
text - Text in the current edit field.
position - Current position of cursor in text.
status - Ignored.
Returns:
If you provide a valid character, this method passes it through unaltered. Otherwise, this method returns the ALTed version of the provided character.
Since:
BlackBerry API 4.2.0

validate

public boolean validate(char character)
Determines if character is valid numeric string character.

Specified by:
validate in class TextFilter
Parameters:
character - Character to test.
Returns:
True if the character is a digit, minus sign, or period; otherwise, false.

validate

public boolean validate(char character,
                        AbstractString text,
                        int position)
Determines if character is valid numeric string character.

Overrides:
validate in class TextFilter
Parameters:
character - Character to test.
text - Text in the current edit field.
position - Current position of cursor in text.
Returns:
True if the character is a digit, minus sign at the beginning of the number, or period; otherwise, false.
Since:
BlackBerry API 4.2.0

validate

public boolean validate(AbstractString text)
Determines if provided string contains valid numeric characters.

This method checks each character in your provided string with NumericTextFilter.validate(char) for validity. It does no checking that your string is well formed numeric text, with one exception: this method returns true if the string contains only a single minus sign (if this filter allows negative numbers).

Overrides:
validate in class TextFilter
Parameters:
text - String to check.
Returns:
True if each character in the string passes a validity check, with an optional minus sign at the begining; otherwise, false.





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal