views:

43

answers:

2

Given a multi-line EditText, how can I know the line number at cursor position?

A: 

Take the text of the control and put it in a string. Loop over the string up to the index of the cursor position and count the number of newlines.

wllmsaccnt
The text is wrapped. I has no newlines.
alex2k8
A: 

Something like textview.getPaint().measureText(textview.getText().toString()) / textView.getWidth();

This assumes the cursor is at the end of the text, if not you gotta use substring measure.

Sorry for brevity on my iPad

schwiz