Search code examples
javaandroidandroid-edittextspannablestring

Finding EditText Editable getSpans Start and End Index


I am trying to get All Spans applied to text as below;

public String getTextWithTags(Editable e)
{

    StyleSpan[] ss = e.getSpans(0,e.length(),StyleSpan.class);
    ss[0].getSpanStart <--- ? This is the problem, no such function

    return "";
}

But there is no index find function to replace tags to store them on database so i can retrieve all spans back when i reopen text. How can i get all span positions from editable object?


Solution

  • StyleSpan[] ss = e.getSpans(0,e.length(),StyleSpan.class);
    
    for(StyleSpan span : ss){
        int start = e.getSpanStart(span);
        int end = e.getSpanEnd(span);
    }