Hello I have this extension to apply the styles on...
# android
m
Hello I have this extension to apply the styles on the targeted words, but it doesn't work applying the styles if I send multiple words fro some reason, I tested in a sample project and it works fine .. anyone could help me with it.
Copy code
fun String.applySpans(vararg pairs: Pair<String, Any>): Spannable {
    val spannable = SpannableStringBuilder(this)
    pairs.forEach {
        val start = this.indexOf(it.first)
        val end = start + it.first.length
        spannable.setSpan(it.second, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
    }
    return spannable
}
this is the working version in the test sample
Copy code
val bold = StyleSpan(Typeface.BOLD)
        val italic = StyleSpan(Typeface.BOLD_ITALIC)

        val string = getString(R.string.hello_message, "John", "Wick")

        testTextView.text = string.applySpans(
                "John" to bold,
                "Wick" to italic
        )
this is the code with the problem
Copy code
is AlternateSearchError.NotDeliveringToArea -> {
                searchErrorView.errorAction.visible()
                val message = getString(R.string.not_delivery_to_this_area, searchError.restaurant, searchError.area)
                searchErrorView.errorMessage.text = message.applySpans(
                        searchError.restaurant to bold,
                        searchError.area to bold
                )
            }