views:

667

answers:

1

If I want to enforce a maximum length of input in an EditText field, I can use the maxLength attribute. But if I want to enforce a minimum length (in my case, simply non-blank), I find no corresponding minLength attribute.

I've also looked at the various 'inputType' attributes (phone, password, etc) but I don't see anything like 'required' or 'non-blank'.

I can't believe this would require a custom input filter; it's more likely the answer is so obvious it just doesn't get written down in the form I'm asking the question.

+1  A: 

You can simply check that yourField.text() is not equivalent to null or "" at the point of submission. If it is, prompt the user to input something.

jqpubliq
Maybe also trim the string if you don't want whitespace to count as an imput.
fiXedd
I appreciate both suggestions. And that's essentially what I'm doing -- validating after all fields in the screen are filled in and the user pushes the 'go' button. But what I was looking/hoping for was a way to give instant feedback when focus leaves one field before it goes to the next.
AG
Then you just want to do the check in the `onFocusChanged()` of the EditText
jqpubliq
THAT's what I was missing. I looked at onFocusChanged() but was lead astray by it being a View method so I was thinking it applied to something other than a single field. But, of course, an EditText is a TextView which is, in turn, a View. Thanks.
AG