Limiting text length of Edittext in Sketchware

If you want the user to provide only a certain type of text input in the Edittext field, it can easily be done by selecting appropriate option for input_type from text properties.
The image below shows the input_type options:
However, maxLength or any other option to limit length of input text, is not available in Sketchware. Which means you have to use code blocks in Logic area.

To limit the input text length (suppose to 7 characters), in Edittext: edittext1 
apply InputFilter to the EditText field. In onCreate event, use an add source directly block and put following codes:
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(7);
edittext1.setFilters(filterArray);

This will limit the input text length to the first 7 characters. With this method, if any extra character is entered at the end, it doesn't appear. If there are 7 characters in the EditText field you cannot add more characters.


Comments

  1. what about restricting a character text to only 1 from the speech to text function? please help me

    ReplyDelete
  2. How can you make a button that deletes the last character inputted in the edittext view?

    ReplyDelete
    Replies
    1. Block : edittext1 set text ( let it empty )

      Delete
  3. HELP!! how do you limit number of lines on edittext? I don't want people to keep pressing enter... And also how do you get it to where when u press enter it goes to next bar.. like login screen.

    ReplyDelete
    Replies
    1. You only need to use Single_line option.

      Delete
    2. it is not applicable to the edit text type string

      Delete
  4. Use the code provided below in add source directly block in onCreate event


    edittext1.setFilters(new InputFilter[]{ new InputFilter.LengthFilter(10) });

    ReplyDelete
  5. How can I make it where, once they reach a certain number it disables itself?

    ReplyDelete

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Firebase auth in Sketchware for Login Activity

Simple car racing android game in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Create a PDF reader android App in Sketchware