如何在Android Text View中使用HTML新行功能? [英] How to have HTML New Line Feature in Android Text View?

查看:96
本文介绍了如何在Android Text View中使用HTML新行功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的android应用程序中使用webservice。

假设这是我的web服务结果:



:\ n
  • 马德拉斯发现,新马德拉斯故事,马德拉斯(1992),由S. Muthiah <马德拉斯 - 它的过去和现在(1995)由S. Muthiah
  • \ n
  • 在马德拉斯的家中(1989)由S. Muthiah
  • <\\ n>
  • Chepauk的精神(1998)由S. Muthiah
  • <圣乔治堡的故事<1945年> Col. DM Reid \ n 在Chennai \\\
  • Kalyani的丈夫中饰演的小说SY Krishnaswamy
  • \ n
  • 在钦奈拍摄彩虹 (http://chasingrainbowsinchennai.blogspot.com/\\"> 在钦奈拍摄彩虹),(2003)作者:Colin Todhunter <



我使用Html.fromHtml(String)将其添加到我的TextView中,但我没有获得新的线条功能,我将它显示为一段。



关于金奈的书籍:Madras发现,新旧马德拉斯故事,Madras(1992),S. Muthiah Madras - 它的过去和现在(1995),S. Muthiah Madras - 它的昨日
以及今日和由M。Muthiah创作的Tomorrows在马德拉斯的家中(1989)由S. Muthiah创作Chepauk的精神(1998)由S. Muthiah由圣克里斯纳米在钦奈追逐彩虹(追逐Ra (2003)由Colin Todhunter在老马德拉斯(1914年)by Bithia Mary Crocker


我怎样才能以容易理解的方式呈现这些数据?

解决方案

 字符串sBooks =Chennai上的图书:\\\
.... ;

\\\
替换为< br>

  sBooks = sBooks.replace(\\\
,< br>);

使用TextView的示例:

  myTextView.setText(Html.fromHtml(学生用书)); 


I am using webservice in my android application. In my webservice result I get a HTML formatted String as result.

Assume this is my web service result:

Books on Chennai:\n

  • Madras Discovered, Tales of Old and New Madras, Madras (1992) by S. Muthiah
  • \n
  • Madras – its Past and its Present (1995) by S. Muthiah
  • \n
  • Madras – its Yesterdays and Todays and Tomorrows by S. Muthiah
  • \n
  • At Home in Madras (1989) by S. Muthiah
  • \n
  • The Spirit of Chepauk (1998) by S. Muthiah
  • \n
  • The Story Of Fort St. George (1945) by Col. D.M. Reid
  • \nFiction set in Chennai\n
  • Kalyani’s Husband by S. Y. Krishnaswamy
  • \n
  • Chasing Rainbows in Chennai (http://chasingrainbowsinchennai.blogspot.com/\">Chasing Rainbows in Chennai), (2003) by Colin Todhunter
  • \n
  • In Old Madras (1914) by Bithia Mary Crocker
  • \n

I am using Html.fromHtml(String) to add this to my TextView. But I am not getting new line feature. I displays it as a paragraph.

Books on Chennai: Madras Discovered, Tales of Old and New Madras, Madras (1992) by S. Muthiah Madras – its Past and its Present (1995) by S. Muthiah Madras – its Yesterdays and Todays and Tomorrows by S. Muthiah At Home in Madras (1989) by S. Muthiah The Spirit of Chepauk (1998) by S. Muthiah The Story Of Fort St. George (1945) by Col. D.M. ReidFiction set in Chennai Kalyani’s Husband by S.Y. Krishnaswamy Chasing Rainbows in Chennai (Chasing Rainbows in Chennai), (2003) by Colin Todhunter In Old Madras (1914) by Bithia Mary Crocker

How can I present this data in an easily readable and understandable way?

解决方案

String sBooks = "Books on Chennai:\n ....";

Replace: \n with <br>:

sBooks = sBooks.replace("\n", "<br>");

Example using a TextView:

myTextView.setText(Html.fromHtml(sBooks));

这篇关于如何在Android Text View中使用HTML新行功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆