Android的制作在TextView中点击超链接 [英] Android Make hyperlinks in textview clickable

查看:150
本文介绍了Android的制作在TextView中点击超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到来自服务器的一些HTML和TextView中显示。该HTML有一定的超链接。我想,当用户单击超链接一些,它会打开该链接的URL在设备浏览器,但它不工作。我看了一下Linkify并使用下列内容:

I am getting some HTML from server and showing in Textview. The HTML have some hyperlinks. I want that when user clicks some hyperlink, it opens that link's url in device browser but it is not working. I have read about Linkify and using following:

TextView articleDescription = (TextView)findViewById(R.id.articledescription);
articleDescription.setText(Html.fromHtml(articleInfo.getArticle_body()));
Linkify.addLinks(articleDescription, Linkify.WEB_URLS);

但它也不能正常工作。任何想法... ???

but its too not working. Any idea...???

对不起球员,其实我最近注意到,所以我认为是浏览器的目的不是被解雇的原因是超链接相对于服务器。我有样本HTML文本:

Sorry guys, actually I have recently noticed that the hyperlinks are relative to the server so I think that is the reason the intent for browser is not being fired. I have sample HTML text:

<p><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">Since I began reporting for It&rsquo;s Relevant in June, I have come across some amazing people living and working in Stamford. Over the past 6 months, I have had the opportunity to share their stories and report on issues affecting the city. Here are some of my favorite pieces from     2011:</span></span></p> <p><br /><a href="/content/7298/Bakers_Keep_Up_With_The_Kardashians_?ref=qmf10j"><span style="color: #000080;"><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">Bakers Keep up with the Kardashians</span></span></span></a></p> <p><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">This story combines two of my favorite things, the Kardashian sister&rsquo;s and cake! Deb and Dina are so talented and it was great to see them at work. </span></span></p> <p><br /><a href="www.itsrelevant.com/content/7508/Yankees_GM_Set_To_Jump_Off_Building?ref=qmf10j"><span style="color: #000080;"><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">Yankees GM Set to Jump Off Building</span></span></span></a></p> <p><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">Never in my life did I think I would interview the General Manager of the Yankees, let alone on the rooftop of a 22-story building!</span></span></p> <p><a href="/content/6782/Fashion_Show_Features_Cancer_Survivors?ref=0yk17d"><br /><span style="color: #000080;"><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">Breast Cancer Fashion Show</span></span></span><span style="color: #000000;"><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;"> </span></span></span></a></p> <p><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">These women are truly amazing! So many people are affected by cancer and the Paint the Town Pink committee spent October bringing awareness to the disease. </span></span></p> <p><br /><a href="/content/5275/Downed_Trees_Remain_Problem?ref=qmf10j"><span style="color: #0000ff;"><span style="font-family: Helvetica,sans-serif;"><span style="font-size: small;">Downed Trees Remain Problem </span></span></span></a></p> 

现在任何建议怎样做此种类型的数据?或者某种常规的前pression,这样我可以代替相对路径到服务器的绝对路径?

Now any suggestion what to do which such kind of data? OR some kind of regular expression so that I can replace relative paths to the servers absolute path?

推荐答案

看this.It可能有益。

Look at this.It may Helpfull..

  TextView tv=new TextView(this);
    tv.setLayoutParams(lparams);
    webview =new WebView(this);
    webview.setLayoutParams(lparams);
    tv.setText(Html.fromHtml("<a href='http://www.google.com'>www.google.com</a>"));
    tv.setClickable(true);
    tv.setMovementMethod(LinkMovementMethod.getInstance());
    URLSpan[] urlSpans = tv.getUrls();
    for ( URLSpan urlSpan : urlSpans )  
    {  
        webview.loadUrl( urlSpan.getURL() ); 
    }  

和看这个链接。 http://www.indelible.org/ink/android-linkify/

这篇关于Android的制作在TextView中点击超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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