0

I am developing an android application with some forms. Here in my input fields description section should not allow the user to enter more than 5 lines.I am not getting how to prevent the user to enter more than 5 lines in edit text field. I already tried android:maxLines=5 and android:lines=5. But those are not giving my functionality. could any one please suggest a way to stop entering more than 5 lines in edit text.

Thanks in advance

Raghu Mudem
  • 6,553
  • 12
  • 46
  • 67
  • Check this question here: [EditText maxLines not working - user can still input more lines than set](http://stackoverflow.com/questions/7092961/edittext-maxlines-not-working-user-can-still-input-more-lines-than-set). See the answer by _Indrek Kõue_. – Siddharth Lele Feb 11 '13 at 07:21

4 Answers4

1

The attribute maxLines corresponds to the maximum height of the EditText, it controls the outer boundaries and not inner text lines.

There is no simple way to limit the inputed lines like you want. You'll have to do it manually in your code

jlopez
  • 6,287
  • 2
  • 51
  • 90
0

Validate the field when the user tries to submit it. Use a prompt to notify the user of the required length.

Montycarlo
  • 725
  • 3
  • 16
0

android:maxLines and android:lines limits the number of visible lines, android:maxLines=5 expands the edittext up to 5 lines, and android:lines=5 creates a span of 5 lines.

if you want to limit the length of the input you need to use the android:maxLength=5 as shown in this answer: https://stackoverflow.com/a/3285421/1056359

Community
  • 1
  • 1
thepoosh
  • 12,393
  • 15
  • 70
  • 131
0

mmm, i think this need more calculations depending on font size and the line width, so in this case i prefer just to set the maxLength attribute to like 100 character, otherwise you need to calculate the current text size while user typing into it.

Mohammad Ersan
  • 12,103
  • 8
  • 52
  • 73