From the code you posted, you pass the new gaps to spanStr and ask him to find them. You will need a link to instances of the areas that are actually applied. If this is not possible or you do not want to track gaps directly, you can simply call getSpans to get all the spans. Then you can filter this array for whatever you want.
If you don't care about passages in particular, you can also just call Html.toHtml (spanStr) to get the version tagged with HTML.
edit : add sample code
This will capture all the StyleSpans application styles you want.
StyleSpan[] mSpans = et.getText().getSpans(0, et.length(), StyleSpan.class);
Here is a link to StyleSpan documents.
To select the gaps you want, if you have different gaps mixed with the collection / array, you can use instanceof to find out what sizes you have. This snippet checks to see if a particular mSpan instance of StyleSpan, and then prints its indexes and start and end flags. Flags are constants describing the behavior of range outlines, for example: whether they include and apply styling to text at the beginning and end indices or only for entering text with an index inside the start / end range).
if (mSpan instanceof StyleSpan) { int start = et.getSpanStart(mSpan); int end = et.getSpanEnd(mSpan); int flag = et.getSpanFlags(mSpan); Log.i("SpannableString Spans", "Found StyleSpan at:\n" + "Start: " + start + "\n End: " + end + "\n Flag(s): " + flag); }
KMDev
source share