Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the range of an applied span in SpannableString

I am trying to get the set of applied spans on a SpannableString and then find the ranges in which they have been applied. Is that possible? As far as I have seen, there doesn't seem to be a built in method to do this. Am I right?

Object[] spans = spannableString.getSpans(0, spannableString.length(), Object.class);

    List<Object> spanArray = asList(spans);

    for (Object span: spanArray) {
        if (span.getClass().equals(MyCustomSpan.class)) {
            MyCustomSpan s = (MyCustomSpan) span;

            // Get the range in spannableString where this span has been applied.
            // How do I do this?
        }
    }
like image 807
Rameez Hussain Avatar asked Dec 25 '22 05:12

Rameez Hussain


1 Answers

Call getSpanStart() and getSpanEnd() to retrieve the start and end positions within the Spanned where the span is applied.

like image 126
CommonsWare Avatar answered Dec 28 '22 08:12

CommonsWare