setMovementMethod在android textview中不起作用

时间:2016-05-25 06:44:45

标签: java android html string android-xml

我有一个textview,其文本来自数据库。此文本可以是普通文本,也可以是链接或两者。为此,我使用Html.fromHtml(myText)在html中解析文本。这样就可以检测到链接并显示为可点击。这工作正常。它显示链接的可点击字符串,普通文本不可点击。但是,当我点击该文本时,它不起作用,没有任何反应。 这是我从服务器获取的文字:

Dear user:

Your review titled <a href="http://example.com/review/someText-1069459" target="blank">Normal verified negative 1 desktop</a> on the product <a href="http://example.com/product-reviews/text-925766045"  target="blank">Clickable Text</a> has been resolved.

To check corporate response  <a target="blank" href="http://example.com/interact.php?add=http://example.com/blog/ejhhspsqmn/Please-talk-about-your-companys-products-and-services-onlyPlease-present-your-post-in-an-objectiv&session_id=Se9qExA6JSY%3d">Click here</a>

Have a great day! 

Regards,
Head - Member Support

要制作可点击的文字,我使用如下的setMovementMethod:

textView.setText(Html.fromHtml(myText));
textView.setMovementMethod(LinkMovementMethod.getInstance());

但它不起作用。我在代码中添加了什么?我也在xml中使用android:autoLink="web"

enter image description here

2 个答案:

答案 0 :(得分:1)

删除android:autoLink =&#34; web&#34;在xml。

答案 1 :(得分:1)

您可以使用LinkMoveMethod界面或Linkify

示例:----

TextViewObject.setText(Html.fromHtml("YOur Text "));
TextViewObj.setMovementMethod(LinkMovementMethod.getInstance());

OR

Linkify.addLinks(new SpannableString(Html.fromHtml("Your Text"));