Find the editable getSpans start and end indexes for EditText… here is a solution to the problem.
Find the editable getSpans start and end indexes for EditText
I’m trying to apply all spans to text as follows;
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 lookup feature to replace the tags to store them in the database, so I can retrieve all spans when I reopen the text. How do I get all span positions from an 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);
}