Govind
Govind

Reputation: 2512

Edittext is not accepting number as input type

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

Upvotes: 1

Views: 2910

Answers (4)

Raj
Raj

Reputation: 103

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});

Upvotes: 1

leb1755
leb1755

Reputation: 1424

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

Upvotes: 0

Niraj Niroula
Niraj Niroula

Reputation: 2424

You can use

android:inputType="numberDecimal"

Upvotes: 0

Hulk
Hulk

Reputation: 237

public boolean isLeadingDigit(final String value){
    final char c = value.charAt(0);
    return (c >= '0' && c <= '9');
}

Upvotes: 0

Related Questions