Share via


IInputConnection.GetSelectedTextFormatted(GetTextFlags) Method

Definition

Gets the selected text, if any.

[Android.Runtime.Register("getSelectedText", "(I)Ljava/lang/CharSequence;", "GetGetSelectedText_IHandler:Android.Views.InputMethods.IInputConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Lang.ICharSequence? GetSelectedTextFormatted (Android.Views.InputMethods.GetTextFlags flags);
[<Android.Runtime.Register("getSelectedText", "(I)Ljava/lang/CharSequence;", "GetGetSelectedText_IHandler:Android.Views.InputMethods.IInputConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member GetSelectedTextFormatted : Android.Views.InputMethods.GetTextFlags -> Java.Lang.ICharSequence

Parameters

flags
GetTextFlags

Supplies additional options controlling how the text is returned. May be either 0 or #GET_TEXT_WITH_STYLES.

Returns

the text that is currently selected, if any, or null if no text is selected.

Attributes

Remarks

Gets the selected text, if any.

This method may fail if either the input connection has become invalid (such as its process crashing) or the client is taking too long to respond with the text (it is given a couple of seconds to return). In either case, null is returned.

This method must not cause any changes in the editor's state.

If #GET_TEXT_WITH_STYLES is supplied as flags, the editor should return a android.text.SpannableString with all the spans set on the text.

<strong>IME authors:</strong> please consider this will trigger an IPC round-trip that will take some time. Assume this method consumes a lot of time. If you are using this to get the initial text around the cursor, you may consider using EditorInfo#getInitialTextBeforeCursor(int, int), EditorInfo#getInitialSelectedText(int), and EditorInfo#getInitialTextAfterCursor(int, int) to prevent IPC costs.

<strong>Editor authors:</strong> please be careful of race conditions in implementing this call. An IME can make a change to the text or change the selection position and use this method right away; you need to make sure the returned value is consistent with the results of the latest edits.

Java documentation for android.view.inputmethod.InputConnection.getSelectedText(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to