2012-02-23 3 views
2

서버에서 HTML을 가져 와서 Textview에 표시하고 있습니다. HTML에는 몇 가지 하이퍼 링크가 있습니다. 사용자가 하이퍼 링크를 클릭하면 장치 브라우저에서 해당 링크의 URL이 열리지 만 작동하지 않기를 바래요. Linkify에 대해 읽고 다음 내용을 읽었습니다.Android textview에서 하이퍼 링크를 클릭 할 수있게 만들기

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

그러나 너무 효과가 없습니다. 어떤 생각이든 ... ???

죄송합니다. 실제로 최근에 하이퍼 링크가 서버에 상대적이라는 사실을 알게되었으므로 브라우저의 의도가 해고되지 않은 것으로 생각됩니다. 샘플 HTML 텍스트가 있습니다.

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

이제 어떤 제안을하면 이러한 종류의 데이터를 처리 할 수 ​​있습니까? 또는 어떤 종류의 정규 표현식 그래서 절대 경로를 상대 경로를 서버로 대체 할 수 있습니까? this.It에서

답변

2

봐는 ...

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

을 Helpfull이 링크를 보일 수 있습니다. http://www.indelible.org/ink/android-linkify/

2

과 같이 그 일을보십시오 :

TextView articleDescription = (TextView)findViewById(R.id.articledescription); 
articleDescription.setMovementMethod(LinkMovementMethod.getInstance()); 
articleDescription.setText(Html.fromHtml(articleInfo.getArticle_body())); 
1

방법이에 대한

TextView t2 = (TextView) findViewById(R.id.*example*); 
t2.setMovementMethod(LinkMovementMethod.getInstance()); 
관련 문제