Search code examples
androidandroid-inputtype

How to set the "InputType" of "EditText" that only can be inputed by "0123456789" and "." in java code


How to set the "InputType" of "EditText" that only can be inputed by "0123456789" and "." in java code? I just konw I can make it by android:digits="0123456789." in XML,but I want to make it in jave code, I have tried to editText.setInputType(),but there is no this type.


Solution

  • Try this it worked for me.

    editText.setKeyListener(DigitsKeyListener.getInstance("0123456789."));