0

For an Assignment I have to implement an App that simplifies SMS writing, eg. for elderly people.

What im am now trying to do is:

I have an EditText that need to be limited to 5 lines and 255 Characters total.

Both constraints have to be met. Meaning the person can write 255 of any character but if he/she gets to the end of the 5th Line, no matter how much under 255 characters he/she is, the EditText should not write anything out. Same shoudl happen if he hits 255 characters in the second line.

I hope i could make clear what i need.

Thanks in advance for any help!

Ps. I know simply not responding is a bad practice, but i just want this to work, i will figure out a way to notify the user afterwards by myself.

billdoor
  • 1,999
  • 4
  • 28
  • 54
  • possible duplicate of [Limit text length of EditText in Android](http://stackoverflow.com/questions/3285412/limit-text-length-of-edittext-in-android) – Joseph Earl Jan 05 '14 at 17:42
  • this just solves the porblem of character limitation, but i can with a limit of 255 write 233 newlines and some text afterwards, this shoudl be made impossible too. – billdoor Jan 05 '14 at 17:54
  • You'll either need a custom InputFilter or add TextWatcher and remove anything over the 5 line limit in onAfterTextChanged – Joseph Earl Jan 05 '14 at 17:57

1 Answers1

1

You need to put an InputFilter on the EditText and have it allow or disallow the input. There is already one to limit the total number of characters, you may have to write one yourself to limit based on linecount.

See here for more info: Limit text length of EditText in Android

Community
  • 1
  • 1
Tim B
  • 40,716
  • 16
  • 83
  • 128