There are many editable pop-up boxes in Android, some of which let us modify the characters, where is the cursor position positioned?just solved a bug is about the position of the cursor, it seems that Android native in this case is to position the cursor to the front of the string. The requirement is to position the cursor to the last face of the character. The modification is textview this control, because EditText also inherits the TextView. Among the SetText methods are:
1 private void SetText (charsequence text, Buffertype type,
2 boolean notifybefore, int oldlen) {
3 ...
4 if (text instanceof spannable) {
5 Spannable sp = (spannable) text;
6
7 ...
8 if (mmovement! = null) {
9 Mmovement.initialize (this, (spannable) text);
10//text is not editable.
if (this instanceof Editable)
12//Set cursor position
selection.setselection ((spannable) text, text.length ());
-
.....
+ }
As you can see from the red code, Google wants the cursor to be at the end of the default text, but log discovery (this instanceof Editable) is not true, which means selection.setselection ((spannable) Text, Text.length ()), and will not be executed.
1 log.d ("TextView", "(type = = buffertype.editable) =" + (type = = buffertype.editable));
2 if (type = = buffertype.editable) {
3 LOG.D ("TextView", "Format text". Set cursor to the end ");
4 Selection.setselection ((spannable) text, text.length ());
5}
This kind of modification can be done.
in writing the application, if we want to position the cursor to a location, you can use the following method:
1 charsequence Text = Edittext.gettext ();
2//debug.asserts (text instanceof spannable);
3 if (text instanceof spannable) {
4 spannable Spantext = (spannable) text;
5 selection.setselection (Spantext, Text.length ());
6}
where the Red tag code is the position you want to set, here is the setting to the end of the text.
Android settings EditText cursor position