Android: InputConnection missing getSelection () method

Why do I have setSelectionin InputConnection, but not getSelection()?

Should I just execute getTextBeforeCursor(VERY_HIGH_NUMBER, 0)and compute .length()this line?

+3
source share
2 answers

I agree, stupid that getSelection()does not exist. Your solution works fine, but you should assume that only the cursor is displayed there, and not the entire selected range of text. I have not figured out how to fill this hole.

EDIT: Oh of course:

int selStart = ic.getTextBeforeCursor(HIGH_NUMBER, 0).length();
String sel = ic.getSelectedText(); 
int selEnd = selStart + (sel==null? 0: sel.length());
+1
source

Source: https://habr.com/ru/post/1763467/


All Articles