-
-
Save DVegasa/9521816bbc817c46b51e9b304d398630 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun highlight() { | |
val s = etSearchBar.text | |
adapter.list.forEach { item -> | |
// {1} | |
item.abbr.getSpans(0, item.abbr.length, ForegroundColorSpan::class.java).forEach { | |
item.abbr.removeSpan(it) | |
} | |
// {2} | |
item.name.getSpans(0, item.name.length, ForegroundColorSpan::class.java).forEach { | |
item.name.removeSpan(it) | |
} | |
// {3} | |
if (item.abbr.startsWith(s, true)) { | |
item.abbr.setSpan(spanHighlight, 0, s.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) | |
} | |
// {4} | |
if (item.name.contains(s, true)) { | |
val index = item.name.toString().indexOf(s.toString(), 0, true) | |
item.name.setSpan(spanHighlight, index, index + s.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment