Android EditText enforces a numeric keypad but allows non-numeric characters

I need to maintain EditText, which can be entered by the user by numbers, in some cases I need to set the text EditTextto something like $ 12. Therefore, I need to be able setText()to everything I want.

I tried setting up an EditText with an input type set to a number that gives a numeric keypad, and also removes InputFilterthat EditText - which still prevents me from putting non-numeric characters

input.setFilters(new InputFilter[] {});

Am I doing something wrong? Is there another way to accomplish my goal, EditText with a numeric keypad, which I can programmatically insert some non-numeric characters into?

+4
source share
3 answers

This will contain a numeric value, but will allow you to use the $ character, add any other special characters you need for the attribute android:digits

<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:digits="0123456789,$">
+7
source

Just add an aviran answer. If you put any "," in a string, you will also allow commas in the EditText.

Only 0-9 and $ will be allowed below.

<EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:digits="0123456789$">

+2
source

Set the input type to Phone in xml.

It can help you ...

how to set only numeric value for edittext in android?

0
source

Source: https://habr.com/ru/post/1534836/


All Articles