Taal

IInputConnectionExtensions.GetTextAfterCursor Method

Definition

Get n characters of text after the current cursor position.

public static string? GetTextAfterCursor(this Android.Views.InputMethods.IInputConnection self, int n, Android.Views.InputMethods.GetTextFlags flags);
static member GetTextAfterCursor : Android.Views.InputMethods.IInputConnection * int * Android.Views.InputMethods.GetTextFlags -> string

Parameters

self
IInputConnection

The input connection on which to call the method.

n
Int32

The expected length of the text. This must be non-negative. Value is 0 or greater

flags
GetTextFlags

Either None or WithStyles.

Returns

The text after the cursor, which can be shorter than n, or null if the request fails.

Remarks

Get n characters of text after the current cursor position.

This method may fail either if 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 seconds to return). In either case, null is returned.

This method does not affect the text in the editor in any way, nor does it affect the selection or composing spans.

If WithStyles is supplied, the editor should return a SpannableString with the text's spans. This extension converts that result to a string without the spans. To access any returned spans, call GetTextAfterCursorFormatted(Int32, GetTextFlags).

Input method authors: this call can take time because it involves interprocess communication. To get initial text around the cursor without that cost, consider GetInitialTextBeforeCursor(Int32, Int32), GetInitialSelectedText(Int32), and GetInitialTextAfterCursor(Int32, Int32).

Editor authors: please be careful of race conditions in implementing this call. An IME can make a change to the text and use this method right away; you need to make sure the returned value is consistent with the result of the latest edits. Also, you may return less than n characters if performance dictates so, but keep in mind IMEs are relying on this for many functions: you should not, for example, limit the returned value to the current line, and specifically do not return 0 characters unless the cursor is really at the end of the text.

Android reference for android.view.inputmethod.InputConnection.getTextAfterCursor.

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