EditText et_description;
--------
et_description = findViewById(R.id.et_description);
----------
private void limitNumberOfLines(int maxLines) {
if (et_description != null) {
int lineCount = et_description.getLineCount();
if (lineCount > maxLines) {
int selectionStart = et_description.getSelectionStart();
int selectionEnd = et_description.getSelectionEnd();
et_description.setText(et_description.getText().toString().substring(0, selectionStart - 1) + et_description.getText().toString().substring(selectionEnd));
et_description.setSelection(selectionStart - 1);
}
}
}