san*_*nic 5 html string android arraylist spanned
我使用以下代码筛选跨区字符串,将所有粗体文本保存为数组中的字符串:
StyleSpan[] spans = storyText.getSpans(0,
storyText.length(), StyleSpan.class);
List<String> boldedWords = new ArrayList<String>();
for (StyleSpan span : spans) {
if (span.getStyle() == Typeface.BOLD) {
//start
int s = storyText
.getSpanStart(span);
//end
int e = storyText.getSpanEnd(span);
boldedWords.add(storyText.subSequence(
s, e).toString());
}
}
String[] array = boldedWords
.toArray(new String[boldedWords.size()]);
Run Code Online (Sandbox Code Playgroud)
但是,我在数组中收到的字符串是乱序的。例如:
句子可能是(大写代表粗体文本):
storyText = "This ADJECTIVE NOUN is VERB"
Run Code Online (Sandbox Code Playgroud)
我要返回的数组是:按“名词、动词、形容词”的顺序排列。应该是:“形容词,名词,动词”
关于为什么会发生这种情况的任何见解?
| 归档时间: |
|
| 查看次数: |
2229 次 |
| 最近记录: |