<EditText
android:id="@+id/editText2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:maxLines="5"
android:lines="5">
</EditText>
User can input more than 5 lines, by pressing enter/next row key. How can I limit user input to fixed amount of rows with EditText?
The attribute
maxLines
corresponds to the maximum height of theEditText
, it controls the outer boundaries and not inner text lines.Here is a InputFilter that limits allowed lines in EditText:
To add it to EditText:
This is what i used in my project:
And it worked in all scenarios
For limit number of characters we can simply use maxLength property of EditText as it will not allow user to enter more characters.