开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜