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?
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,$">
Just to add to aviran's answer. If you put any "," in the string then you will also allow commas in the EditText.
Below will only allow 0-9 and $.
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:digits="0123456789$">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With