Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: InputConnection is missing a getSelection() method

Why do I have a setSelection in InputConnection, but not a getSelection()?

Should I just do a getTextBeforeCursor(VERY_HIGH_NUMBER, 0) and calculate the .length() of that string?

like image 202
znq Avatar asked Oct 14 '22 00:10

znq


1 Answers

I agree, it's silly that getSelection() doesn't exist. Your solution works ok but you have to assume that there's just a cursor showing and not a whole selected range of text. I haven't yet figured out how to fill that 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());
like image 118
CP Taylor Avatar answered Nov 15 '22 11:11

CP Taylor