开发者

How to get a line number under cursor

开发者 https://www.devze.com 2023-01-22 01:12 出处:网络
Given a multi-line EditText, how can I know the li开发者_开发问答ne number at cursor position?Something like

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

精彩评论

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