2012-02-23 2 views
2

Я получаю HTML-код с сервера и показываю в Textview. HTML имеет несколько гиперссылок. Я хочу, чтобы при нажатии пользователем какой-либо гиперссылки он открывает URL-адрес этой ссылки в браузере устройства, но он не работает. Я прочитал о Linkify и используя следующие данные:Android Сделать гиперссылки в textview clickable

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> 

Теперь любое предложение, что делать, какие такие данные? ИЛИ какое-то регулярное выражение, чтобы я мог заменить относительные пути на абсолютный путь серверов?

ответ

2

Посмотрите на this.It может ПОЛЕЗНЫЕ ..

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/

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