Skip to content

Commit c1e79b4

Browse files
author
Gilles Debunne
committed
Fix NPE on Activity start in TextView
Bug 6065279 The selection can be created programatically, and mEditor may be null when it happens. Make sure mEditor is created to display the selection highlight. Change-Id: Idd66a5fd4ad327f9b390b539574e6878c794ba4a
1 parent a16c98c commit c1e79b4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/java/android/widget/TextView.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,8 +2980,7 @@ public void onRestoreInstanceState(Parcelable state) {
29802980
"/" + ss.selEnd + " out of range for " + restored +
29812981
"text " + mText);
29822982
} else {
2983-
Selection.setSelection((Spannable) mText, ss.selStart,
2984-
ss.selEnd);
2983+
Selection.setSelection((Spannable) mText, ss.selStart, ss.selEnd);
29852984

29862985
if (ss.frozenWithFocus) {
29872986
createEditorIfNeeded("restore instance with focus");
@@ -6983,6 +6982,9 @@ protected void onTextChanged(CharSequence text, int start, int lengthBefore, int
69836982
*/
69846983
protected void onSelectionChanged(int selStart, int selEnd) {
69856984
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED);
6985+
// mEditor may be null if selection is created programatically.
6986+
createEditorIfNeeded("onSelectionChanged");
6987+
// Invalidate even when selection range is empty, to remove previous highlight
69866988
getEditor().mTextDisplayListIsValid = false;
69876989
}
69886990

0 commit comments

Comments
 (0)