I want to allow use to enter just 5 lines, I tried this
/** MAX_LINES You want to set */
public void afterTextChanged(Editable editable) {
int lines = mEditText.getLineCount();
if (lines > MAX_LINES) {
String s = editable.toString();
int start = mEditText.getSelectionStart();
int end = mEditText.getSelectionEnd();
if (start == end && start < s.length() && start > 1) {
s = s.substring(0, start - 1) + s.substring(start);
} else {
s = s.substring(0, s.length() - 1);
}
mEditText.setText(s);
mEditText.setSelection(mEditText.getText().length());
// Toast.makeText(RatingActivity.this, "max line set to MAX_LINES", Toast.LENGTH_SHORT).show();
}
This piece of code works for me to set the EditText max lines limit to MAX_LINES.