How to get a line number under cursor
Given a multi-line EditText, how can I know the li开发者_开发问答ne number at cursor position?
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
There exists a workaround for your problem.
This SO question may give you some further insights: How to get number of rows in ContentEditable area and current caret line position?
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.
精彩评论