Android Question Dynamically limit EditText field?

In HTML forms, you can set a MaxLength field to a form input, (which you can also do in Android Studio) but I can't see a way to do it in B4A. Annoyingly, in my app, some fields can only take 64 chars, some 128 and one up to 2000. I know I can check AFTER the event, but I wont to stop them on the form itself.

Plus, I know it can be done with Javascript.

Would I have to call a sub each time the EditText changes, and do something like a

If len.xyz <64 then
....
else
MsgBox ("limitReached")

type scenario?

Just thought I'd check to see if there is an easier way before I code it.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Thanks for the reply. I actually managed to solve it myself in my first ever B4A script!! All I needed was a call to a sub routine each time the field was typed into via a "Text_Changed" sub, find the length of new, and then use an "If Then" loop to 'lock out' at X chars. (I even took it one stage further, and had the count update a label on the panel, so now the user sees "1 of 64" ... "10 of 64" etc until they hit the limit!)

Feel quite smug that I was able to do all that first go!
 
Upvote 0
Top