1

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.

zys
  • 1,306
  • 3
  • 18
  • 37
  • EditorInfo.TYPE_NUMBER_FLAG_DECIMAL maybe it works – zys Oct 23 '15 at 03:37
  • https://stackoverflow.com/questions/11519214/set-edittext-using-only-0123456789-programmatically-in-android?rq=1 – Shmuel Oct 23 '15 at 03:38
  • http://developer.android.com/reference/android/widget/TextView.html#attr_android%3ainputType – zys Oct 23 '15 at 03:51

1 Answers1

2

Try this it worked for me.

editText.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
DroidAks
  • 327
  • 2
  • 9
  • right,and `TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_DECIMAL` is also useful thank u – zys Oct 23 '15 at 10:09