Limit the input in an edit text

70 views Asked by At

I want to write a input filter such that if i say the edit text should not have a number higher than 40 you can input 1-40 , but anything else will not work

I do not want to do that with a text watcher, but an InputFilter

how can I do that ?

1

There are 1 answers

2
Sarthak Mittal On

There's a property of EditText (in xml) called:

android:inputType="number"    

You might be having a button click or something during which you would validate the EditText, there you can do something like this:

int num = Integer.parseInt(editText.getText().toString());
if(num<1 || num>40)
{
  // display a message that you have to write something to EditText first
}