jam*_*mes 2 android format-specifiers xml-parsing jsoup
我正在开发一个应用程序,在该应用程序中我使用来自站点的 jsoup 解析 XML 文件并将其显示在 textview 上。我遇到的问题是 RSS 中包含的格式说明符 \n 不是 wprking。而不是进入新行,它只是显示 \n 原样。这是我的代码
hello = sb.toString();
String title, description = null;
Document document = Jsoup.parse(hello);
Elements a = document.getElementsByTag("item");
for (Element element : a) {
title = element.child(0).text();
description = element.getElementsByTag("description").get(0).text();
String src = Jsoup.parse(description).select("img").first().attr("src");
String id = Jsoup.parse(description).select("id").text();
description = Jsoup.parse(description).text();
description = description.replace(id, "");
description = description.replace("/", "\\");
list.add(new News(title, id, src, description ));
Run Code Online (Sandbox Code Playgroud)
描述包含 \n 标签,但在文本视图中它不起作用,如图所示。正如您在第一行中看到的那样,而不是进入新行 \n 显示原样。

试试这个:
description= description.replaceAll("\\n", System.getProperty("line.separator"));
Run Code Online (Sandbox Code Playgroud)
因为斜杠 \ 必须是一种“castet”,所以你可以用一个斜杠 \ 来做。
| 归档时间: |
|
| 查看次数: |
4257 次 |
| 最近记录: |