Android Question Dynamically limit EditText field?

Discussion in 'Android Questions' started by Cristofayre, Mar 23, 2015.

  1. Cristofayre

    Cristofayre Member

    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.
     
  2. DonManfred

    DonManfred Expert Licensed User

  3. Cristofayre

    Cristofayre Member

    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!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice