0

I know that limiting the text length of EditText can be done using the maxLength attribute in xml or using InputFilter using the below approaches

Using xml

android:maxLength="10"

Using InputFilter

myEditText.filters = arrayOf(InputFilter.LengthFilter(10))

But I want to enable user to type as many characters as they want while limiting the number of characters that can be pasted into the EditText using clipboard. How can I achieve this? Thanks!

Ryan M
  • 18,333
  • 31
  • 67
  • 74
varunkr
  • 5,364
  • 11
  • 50
  • 99
  • 1
    Curious why you care where the characters are coming from? But one idea would be to set a text change listener on the EditText and check the changed text. If it's +/- 1 character, they typed, if it's more than that, they pasted. – dominicoder Apr 21 '23 at 15:30
  • @dominicoder Might want to double-check if inserting completions from a keyboard enters multiple characters at once; I'm not sure if it does. – Ryan M Apr 21 '23 at 20:27

0 Answers0