Assigned
Status Update
Comments
aa...@gmail.com <aa...@gmail.com> #2
This is considerably easier to reproduce.
We get the same thing on multiple 5.x devices using Html.fromtext("some html text with links"); setSelectable(true);
We get the same thing on multiple 5.x devices using Html.fromtext("some html text with links"); setSelectable(true);
aa...@gmail.com <aa...@gmail.com> #3
Try this as a workaround for the issue:
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (selStart == -1 || selEnd == -1) {
// @hack :https://code.google.com/p/android/issues/detail?id=137509
CharSequence text = getText();
if (text instanceof Spannable) {
Selection.setSelection((Spannable) text, 0, 0);
}
} else {
super.onSelectionChanged(selStart, selEnd);
}
}
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (selStart == -1 || selEnd == -1) {
// @hack :
CharSequence text = getText();
if (text instanceof Spannable) {
Selection.setSelection((Spannable) text, 0, 0);
}
} else {
super.onSelectionChanged(selStart, selEnd);
}
}
aa...@gmail.com <aa...@gmail.com> #4
setSelection 0,1 is probably better to avoid both selectors on top of eachother. Possibly cutting it to the first word or something like that.
ri...@gmail.com <ri...@gmail.com> #5
Good workaround from aagaa. Just to clarify in case anyone else got confused for a second, he is saying to create a custom TextView and override that function he is providing.
From what I can tell, the problem is when you scroll in the ListView, the focus is removed from the textview, and the setSpan(-1,-1) is called.
From what I can tell, the problem is when you scroll in the ListView, the focus is removed from the textview, and the setSpan(-1,-1) is called.
al...@android.com <al...@android.com>
gr...@gmail.com <gr...@gmail.com> #6
Workaround from aagaa has a big trouble.
Calling this - Selection.setSelection((Spannable) text, 0, 0); for TextView inside ScrollView perform scroll to top.
Calling this - Selection.setSelection((Spannable) text, 0, 0); for TextView inside ScrollView perform scroll to top.
[Deleted User] <[Deleted User]> #7
Any update on this? I'm still seeing the behavior happen in AppCompatTextView in version 25.
ro...@google.com <ro...@google.com>
si...@google.com <si...@google.com>
st...@google.com <st...@google.com> #8
LinkMovementMethod - ownership transfer
si...@google.com <si...@google.com>
73...@qq.com <73...@qq.com> #9
seems not fixed yet
mm...@gmail.com <mm...@gmail.com> #10
received this crash from client with android 7.0 and Samsung Galaxy Halo
sa...@google.com <sa...@google.com> #11
Thank you for your feedback. We assure you that we are doing our best to address all issues reported. For now, we will be closing the issue as won't fix obsolete. If this issue currently still exists, we request that you log a new issue along with the bug report here https://goo.gl/TbMiIO and reference this bug for context.
bd...@google.com <bd...@google.com> #12
Reopening issues that had been marked with hotlistid:4240 to prevent bulk closure.
pa...@outlook.com <pa...@outlook.com> #13
It's 2024, and this is still happening on Android 8.1 and Android 10
Description
crash report:
02-05 13:10:45.589: E/AndroidRuntime(19263): FATAL EXCEPTION: main
02-05 13:10:45.589: E/AndroidRuntime(19263): Process: com.test.test, PID: 19263
02-05 13:10:45.589: E/AndroidRuntime(19263): java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.text.SpannableStringInternal.checkRange(SpannableStringInternal.java:357)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:79)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.text.SpannableString.setSpan(SpannableString.java:46)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.text.Selection.setSelection(Selection.java:76)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.widget.Editor$SelectionEndHandleView.updateSelection(Editor.java:3725)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.widget.Editor$HandleView.positionAtCursorOffset(Editor.java:3360)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.widget.Editor$SelectionEndHandleView.updatePosition(Editor.java:3740)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.widget.Editor$HandleView.onTouchEvent(Editor.java:3480)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.View.dispatchTouchEvent(View.java:8388)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.View.dispatchPointerEvent(View.java:8578)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4021)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3887)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3578)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3635)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5701)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5675)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5646)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5791)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5762)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5814)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.Choreographer.doFrame(Choreographer.java:548)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.os.Handler.handleCallback(Handler.java:739)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.os.Handler.dispatchMessage(Handler.java:95)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.os.Looper.loop(Looper.java:135)
02-05 13:10:45.589: E/AndroidRuntime(19263): at android.app.ActivityThread.main(ActivityThread.java:5221)
02-05 13:10:45.589: E/AndroidRuntime(19263): at java.lang.reflect.Method.invoke(Native Method)
02-05 13:10:45.589: E/AndroidRuntime(19263): at java.lang.reflect.Method.invoke(Method.java:372)
02-05 13:10:45.589: E/AndroidRuntime(19263): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
Steps to reproduce:
Include TextView in xml:
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/black"
android:textColorHighlight="@color/gray_lite"
android:textColorLink="@drawable/ink_textcolorhighlight"
android:textSize="16sp" />
Then in code:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setMessage() {
TextView tv = findViewById(R.id.tv1);
tv.setText("Visiting
Linkify.addLinks(tv, Linkify.ALL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
tv.setMovementMethod(new CustomMovementMethod()); /* with or without this line it crashes in Nexus 5, but with this line it works well upto 4.4. The CustomMovementMethod is taken from
tv.setTextIsSelectable(true);
}
}
public static class CustomMovementMethod extends LinkMovementMethod {
@Override
public boolean canSelectArbitrarily () {
return true;
}
@Override
public void initialize(TextView widget, Spannable text) {
Selection.setSelection(text, text.length());
}
@Override
public void onTakeFocus(TextView view, Spannable text, int dir) {
if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) {
if (view.getLayout() == null) {
// This shouldn't be null, but do something sensible if it is.
Selection.setSelection(text, text.length());
}
} else {
Selection.setSelection(text, text.length());
}
}
}
Behavior:
Till 4.4 it works well with CustomMovementMethod it works well as all links work and is also selectable for copy. But it crashes in Nexus 5 when trying to select text as described above (also without setting the MovementMethod). Please correct me, if I am doing something wrong.