首页 新闻 会员 周边

请问安卓的EditText中有没有获取光标所在行号的方法

0
悬赏园豆:5 [已解决问题] 解决于 2014-08-26 20:15

请问安卓的EditText中有没有获取光标所在行号的方法,或者有没有可以实现这个要求的方法。至少我百度了很久都没有发现解决方案

登天路的主页 登天路 | 初学一级 | 园豆:186
提问于:2014-08-23 10:08
< >
分享
最佳答案
0

没有听说过用百度可以找到开发员需要的资料的。我们都使用火星上才有的搜索Google。

for current Cursor Line try this:

public int getCurrentCursorLine(EditText editText) { int selectionStart = Selection.getSelectionStart(editText.getText()); Layout layout = editText.getLayout(); if (!(selectionStart == -1)) { return layout.getLineForOffset(selectionStart); } return -1; }

and for Cursor position use getSelectionStart() :

int cursorPosition = myEditText.getSelectionStart();

收获园豆:5
爱编程的大叔 | 高人七级 |园豆:30839 | 2014-08-23 12:35

谢谢,问题已经解决。不过现在上Google有点难度,所以才习惯性的用百度

登天路 | 园豆:186 (初学一级) | 2014-08-23 13:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册