开发者

Get whole text before the cursor

I need get whole text string before the cursor in my InputMethod clas开发者_如何学Cs. getTextBeforeCursor() gets only "n" characters, but I don't know text's length.


See this documentation. It seems that you can do this:

getCurrentInputConnection().getTextBeforeCursor(100, 0);

or some other large number since it only takes the text from the input - not all the 'n' characters.


Try this.This should work.

//get the input connection first
InputConnection iconn = getCurrentInputConnection();
//get the total text first.
String full_text=iconn.getExtractedText(new ExtractedTextRequest(),0).text.toString();
//get whole text before the cursor
String before_text=iconn.getTextBeforeCursor(full_text.length(),0).toString();


As was said above you can use getTextBeforeCursor() with large number. If it return string with same length, you can try get bigger one. But be careful, some applications, like email app from Samsung return whole length string! Even if you type 1 character.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜