[英]How to make link “a href=” in TextView clickable without using .setText(Html.FromHtml)
i'm doing the rss reader and i need your help. 我正在做rss阅读器,我需要您的帮助。 I'm parsing an xml file and getting the next content of tag 我正在解析一个xml文件并获取标记的下一个内容
<p>
<img class="alignright size-full wp-image-115203" alt="10 мероприятий, которые можно посетить в марте" src="http://ain.ua/wp-content/uploads/2013/03/secr2011-nov1-300x200.jpg" width="300" height="200" title="10 мероприятий, которые можно посетить в марте"
/>Предлагаем вашему вниманию небольшой список ИТ мероприятий марта, которые пройдут в Украине. В нашем
<a href="http://ain.ua/events">календаре мероприятий</a>, вы можете найти еще больше мероприятий, которые мы рекомендуем вам к посещению.</p>
<ol>
<li>
<a href="http://ain.ua/event/seminar-kpi-motivaciya-sistema-oplaty-po-rezultatu">Семинар “KPI-Мотивация. Система оплаты по результату”</a>
</li>
<li>
<a href="http://ain.ua/2013/03/04/114970">Бесплатный семинар об организации системы внутренних коммуникаций и мотивации сотрудников</a>
</li>
<li>
<a href="http://ain.ua/event/targetirovaniya-reklamnyx-kampanij-po-celevym-auditoriyam">Круглый стол «Возможности таргетирования рекламных кампаний по целевым аудиториям»</a>
</li>
<li>
<a href="http://ain.ua/event/kak-zastavit-sajt-prodavat-bolshe">Бесплатный вебинар «Как заставить сайт продавать больше?»</a>
</li>
<li>
<a href="http://ain.ua/event/6-j-seminar-effektivnyj-internet-marketing-dlya-biznesa">6-й семинар «Эффективный интернет-маркетинг для бизнеса»</a>
</li>
<li>
<a href="http://ain.ua/event/internet-marketing-2013">Всеукраинский Форум «Дни Интернет-маркетинга» 2013</a>
</li>
I need that all of these links where clickable and with name beetwen name_of_link 我需要所有这些链接都可以单击并且名称为beetwen name_of_link
I have the next code, wich parsing needed xml-file 我有下一个代码,将解析所需的xml文件
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
String xml = XMLfunctions.getXML(resourceURL);
Document doc = XMLfunctions.XMLfromString(xml);
NodeList nodes = doc.getElementsByTagName("item");
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put(KEY_TITLE, XMLfunctions.getValue(e, KEY_TITLE));
map.put(KEY_DATE_TIME, "Date: "+XMLfunctions.formatDate(XMLfunctions.getValue(e, KEY_DATE_TIME)));
map.put(KEY_DESC, Html.fromHtml(XMLfunctions.getValue(e, KEY_DESC),null,null).toString());
map.put(KEY_LINK, Html.fromHtml(XMLfunctions.getValue(e, KEY_LINK)).toString());
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main,
new String[] { "title","pubDate", "description","link" },
new int[] { R.id.item_title, R.id.item_pubdate, R.id.item_subtitle, R.id.item_link });
setListAdapter(adapter);
My question is : how to parse and transform data that in output i will get normal text with clickable links, like in this source http://feeds.feedburner.com/ainua?format=xml 我的问题是:如何解析和转换输出中的数据,我将获得带有可单击链接的普通文本,例如此源中的http://feeds.feedburner.com/ainua?format=xml
I'm very sorry for wasting your time if this arcticle is already exist, but unfortunately, i don't know how to fing it. 非常抱歉浪费您的时间,如果这个弧线已经存在,但是不幸的是,我不知道该如何应对。 Any help is appreciated, because i've spend many hours trying to resolve this task, but i don't where i need to look for. 感谢您的帮助,因为我花了很多时间尝试解决此任务,但是我不需要寻找任何地方。 Thx. 谢谢。
我将尝试为ListView实现我自己的Adapter-Class并修改为适配器相应方法中的每一行创建的视图。
You need to parse the HTML yourself if you don't want to use HTML.fromHTML()
, while you can easily fetch the href
links with RegEx, you still need to handle the image tags, lists, etc so RegEx is not the real answer. 如果您不想使用HTML.fromHTML()
,则需要自己解析HTML,尽管可以轻松地使用RegEx提取href
链接,但仍然需要处理图像标签,列表等,因此RegEx不是真正的回答。 This question should help: Parse HTML in Android 这个问题应该有所帮助: 在Android中解析HTML
In case you decide to try parsing the HTML with RegEx, please read: RegEx match open tags except XHTML self-co҉ntained tags . 如果您决定尝试使用RegEx解析HTML,请阅读: RegEx匹配除XHTML自包含标记之外的其他开放标记 。 It explains why RegEx cannot do th̵is. 它解释了为什么RegEx无法做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.