1

I cannot enter number (numeric) in the Edittext field.

If I keep android:inputType="text", number cannot be entered.
If I keep android:inputType="text|number", the keyboard accepts only digits.

But If I keep android:inputType="textMultiLine", I can enter both text/number but the first character cannot be number and it should be a character.

And I tried doing with other options too, nothing worked. I'm building the application with the target sdk:21

Note: I need both text / number as input

Samir Bhatt
  • 3,041
  • 2
  • 25
  • 39
Govind
  • 2,482
  • 1
  • 28
  • 40

4 Answers4

1
InputFilter filter = new InputFilter() { 
  public CharSequence filter(CharSequence source, int start, int end, 
    Spanned dest, int dstart, int dend) {
      for (int i = start; i < end; i++) { 
        if (!Character.isDigit(source.charAt(i))) { 
            return ""; 
        }
      }
      return null; 
    } 
}; 
your_edit_text.setFilters(new InputFilter[]{filter});
Raj
  • 103
  • 9
0
public boolean isLeadingDigit(final String value){
    final char c = value.charAt(0);
    return (c >= '0' && c <= '9');
}
Hulk
  • 237
  • 1
  • 13
0

You can use

android:inputType="numberDecimal"
Niraj Niroula
  • 2,376
  • 1
  • 17
  • 36
  • 1
    I think this'll help you [http://stackoverflow.com/questions/3544214/edittext-with-number-keypad-by-default-but-allowing-alphabetic-characters/28694835#comment46661555_14476449] – Niraj Niroula Mar 27 '15 at 13:41
0

Try to not specify inputType or set it to "none" if you want to be able to enter text and numbers.

leb1755
  • 1,386
  • 2
  • 14
  • 29