diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-20 07:38:31 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-20 07:38:31 -0800 |
commit | 15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b (patch) | |
tree | d03d027a7ed97af616904e02a7b420babf40d44f /core/java/android/widget/TextView.java | |
parent | 3001a035439d8134a7d70d796376d1dfbff3cdcd (diff) | |
download | frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.zip frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.tar.gz frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.tar.bz2 |
auto import from //branches/cupcake/...@132569
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r-- | core/java/android/widget/TextView.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index bdc54ff..c852be5 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -4132,8 +4132,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener removeParcelableSpans(content, start, end); content.replace(start, end, text.text); } - Selection.setSelection((Spannable)getText(), - text.selectionStart, text.selectionEnd); + + // Now set the selection position... make sure it is in range, to + // avoid crashes. If this is a partial update, it is possible that + // the underlying text may have changed, causing us problems here. + // Also we just don't want to trust clients to do the right thing. + Spannable sp = (Spannable)getText(); + final int N = sp.length(); + int start = text.selectionStart; + if (start < 0) start = 0; + else if (start > N) start = N; + int end = text.selectionEnd; + if (end < 0) end = 0; + else if (end > N) end = N; + Selection.setSelection(sp, start, end); } /** |