androidandroid-edittextandroid-input-filter

Android EditText force numeric keyboard but allow non-numeric chars


I need to maintain an EditText which can be inputted by the user numbers, at some cases I need to set the text of the EditText to something like 12$. So I need to be able to setText() to anything I want.

I've tried setting up an EditText with input type set to number which yields the numeric keypad and also remove the InputFilter's of that EditText - Which still does not allow me to put non numeric chars

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

Am I doing something wrong? Is there a different way to accomplish my goal, an EditText with a numeric keypad that i can programmatically insert some non numeric chars into?


Solution

  • This will keep it numeric but will allow the $ character, add any other special chars you need to the android:digits attribute

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