Reputation: 683
So the easiest way for the edittext to format your input is to use the phone inputType. The problem is that this gives you a few other symbols other then numbers. And I don't want the user to be able to type in those symbols.
Is there a trick that i could do to get this to work? Other then writing a custom textWatcher that formats the text.
Upvotes: 0
Views: 234
Reputation: 119
You should use as Athira pointed:
android:inputType="number"
and if you want decimal numbers then:
android:inputType="numberDecimal"
Upvotes: 0
Reputation: 576
If you want to show only numbers in your keyboard just like this screenshot
You have to use numberPassword
input type instead of phone
input type
android:inputType="numberPassword"
But when you apply this your entries in editText
appear as bullets because inputType
is numberPassword
, So to solve this problem make a new java class for example:
public class NumberKeyPadTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return source;
}}
And in your main activity
where you fetch the ids of edittext
or where you use that edittext
you have to simply add one line of code
editText.setTransformationMethod(new NumberKeyPadTransformationMethod());
Your whole problem will solve.
Hope this will help you.
Upvotes: 2