The lines may be different:
- Visible lines: wrapped text as a new line ...
- List item: only lines with \ r, \ n, \ r \ n
The first case (the simplest):
int nbLines = editText.getLineCount();
Second case:
int nbLines = 0;
StringReader sr = new StringReader(editText.getText().toString());
LineNumberReader lnr = new LineNumberReader(sr);
try {
while (lnr.readLine() != null){}
nbLines = lnr.getLineNumber();
lnr.close();
} catch (IOException e) {
nbLines = editText.getLineCount();
} finally {
sr.close();
}
source
share