Rocky Zhang
Rocky Zhang

Reputation: 1320

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.

Upvotes: 1

Views: 212

Answers (1)

DroidAks
DroidAks

Reputation: 327

Try this it worked for me.

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

Upvotes: 2

Related Questions