Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 825
Mert Serimer Avatar asked Aug 25 '15 11:08

Mert Serimer


2 Answers

StyleSpan[] ss = e.getSpans(0,e.length(),StyleSpan.class);

for(StyleSpan span : ss){
    int start = e.getSpanStart(span);
    int end = e.getSpanEnd(span);
}
like image 174
mstrengis Avatar answered Oct 31 '22 22:10

mstrengis


If u want to find Span start/end index, you can use this(example for a single RelativeSizeSpan) -

val sb = text as SpannableStringBuilder
val firstSpan = getSpans(0, length, RelativeSizeSpan::class.java).first()
val start = (sb as Spanned).getSpanStart(firstSpan)
val end = (sb as Spanned).getSpanEnd(firstSpan)
like image 44
Vladislav Shcherbakov Avatar answered Oct 31 '22 22:10

Vladislav Shcherbakov