Q:

Android Development: Count EditText Lines on textChanged?

How can I count the number of lines in an EditText?
Basically in my app I have line numbers and I wanted to make them update on textchange (I already have the textchangelistener set up).
Is this possible? :(
Thanks,
Alex!

A:

Lines can be differents:

Visible lines: Wrapped text count as a new line...
List item: Only lines with \r, \n, \r\n

First case (the easiest):
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();
        }

