IInputConnection.GetTextBeforeCursorFormatted(Int32, GetTextFlags) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Get <var>n</var> characters of text before the current cursor position.
[Android.Runtime.Register("getTextBeforeCursor", "(II)Ljava/lang/CharSequence;", "GetGetTextBeforeCursor_IIHandler:Android.Views.InputMethods.IInputConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Lang.ICharSequence? GetTextBeforeCursorFormatted (int n, Android.Views.InputMethods.GetTextFlags flags);
[<Android.Runtime.Register("getTextBeforeCursor", "(II)Ljava/lang/CharSequence;", "GetGetTextBeforeCursor_IIHandler:Android.Views.InputMethods.IInputConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member GetTextBeforeCursorFormatted : int * Android.Views.InputMethods.GetTextFlags -> Java.Lang.ICharSequence
Parameters
- n
- Int32
The expected length of the text. This must be non-negative.
- flags
- GetTextFlags
Supplies additional options controlling how the text is
returned. May be either 0
or #GET_TEXT_WITH_STYLES
.
Returns
the text before the cursor position; the length of the returned text might be less than <var>n</var>.
- Attributes
Remarks
Get <var>n</var> characters of text before the current cursor position.
This method may fail either if the input connection has become invalid (such as its process crashing) or the editor 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 #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. Also, please keep in mind the Editor may choose to return less characters than requested even if they are available for performance reasons. 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 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 start of the text.
Java documentation for android.view.inputmethod.InputConnection.getTextBeforeCursor(int, 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.