TextUtil.concat不保留超链接

时间:2010-09-20 23:23:31

标签: android

例如,以下代码可以正常使用

CharSequence text = TextUtils.concat( "before ", Html.fromHtml( "<b>This works</b>"), " after " );
myTextView.setText(text, TextView.BufferType.SPANNABLE );

如果我在html代码中加了一个超链接,即

CharSequence text = TextUtils.concat( "before ", Html.fromHtml( "<a href=\"www.google.it\">Google</a>"), " after " );
myTextView.setText(text, TextView.BufferType.SPANNABLE );
Linkify.addLinks( myTextView, Linkify.ALL );

显示“Google”,但超链接未正确删除,且无法点击。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

删除第Linkify.addLinks( myTextView, Linkify.ALL );行,并在textsetText声明之间放置以下一行:

classNameTextView.setMovementMethod(LinkMovementMethod.getInstance());