简体   繁体   中英

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. I'm parsing an xml file and getting the next content of tag

<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

I have the next code, wich parsing needed xml-file

        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

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. This question should help: Parse HTML in Android

In case you decide to try parsing the HTML with RegEx, please read: RegEx match open tags except XHTML self-co҉ntained tags . It explains why RegEx cannot do th̵is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM