代码之家  ›  专栏  ›  技术社区  ›  Mushahid Hussain

\n无法在textview android中工作

  •  2
  • Mushahid Hussain  · 技术社区  · 9 年前

    我正在开发一个应用程序,在该应用程序中,我使用来自站点的jsoup解析一个XML文件,并将其显示在textview上。我遇到的问题是RSS中包含的格式说明符不是wparking。而不是进入新的一行,它只是显示它的样子。这是我的代码

        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 ));
    

    描述包含标记,但在文本视图中,它无法如图所示工作。正如您在第一行中看到的那样,而不是进入显示原样的新行。 enter image description here

    2 回复  |  直到 9 年前
        1
  •  6
  •   Opiatefuchs    9 年前

    试试这个:

     description= description.replaceAll("\\n", System.getProperty("line.separator"));
    

    因为斜线必须是一种“种姓”,所以你可以用一个斜线。

        2
  •  2
  •   darnmason    9 年前

    可能添加另一个替换调用来替换 "\\n" 具有 "\n"