Fix search note by title, throws java.lang.IndexOutOfBoundsException: setSpan (19 ... 20)

This commit is contained in:
xingxing
2018-01-10 00:25:38 +08:00
parent 4bec20faaa
commit 5188bb7bf0

View File

@@ -237,11 +237,12 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.NoteHolder> {
}
private CharSequence getHighlightedText(String text) {
String newText = HtmlUtils.delHTMLTag(text);
if (mTitleHighlight == null) {
return HtmlUtils.delHTMLTag(text);
return newText;
}
SpannableStringBuilder builder = new SpannableStringBuilder(HtmlUtils.delHTMLTag(text));
Matcher matcher = mTitleHighlight.matcher(text);
SpannableStringBuilder builder = new SpannableStringBuilder(newText);
Matcher matcher = mTitleHighlight.matcher(newText);
int color = 0xFFFDD835;
while (matcher.find()) {
builder.setSpan(new BackgroundColorSpan(color), matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);