Link 在 Android 文本视图上

Link on a Android textView

我正在尝试将 link 放在 textview 上,但是当我单击此 link 时,应用程序中断了!!这是我的代码:

final TextView msg = (TextView)view_aux.findViewById(R.id.accordion_msg);
msg.setText(Html.fromHtml(dbStructure.getMsg()));
msg.setTypeface(tF);
msg.setTextColor(Color.DKGRAY);
msg.setMovementMethod(LinkMovementMethod.getInstance());

其中dbStructure.getMsg()returns一个String。这个字符串可能是这样的:

< a href="/reference/android/widget/RelativeLayout.html">RelativeLayout< /a> 

让子视图指定它们相对于父视图或彼此的位置(由 ID 指定)。因此,您可以通过右边框对齐两个元素,或使一个元素位于另一个元素下方、屏幕居中、居左等等。

看起来不错,但是当我按下它时应用程序停止了。

编辑
抛出的错误 ActivityNotFoundException.

您尝试打开的 link 已损坏

/reference/android/widget/RelativeLayout.html

上面没有对应的link.

用正确的 url 替换它

http://developer.android.com/reference/android/widget/RelativeLayout.html

非常感谢大家...问题是(正如@Antonio @danidee @TheRedFox 和@Arslan 所说)url 的格式...它不是以 http 开头. 征得大家的同意,我来回答我自己的问题:

final TextView msg = (TextView)view_aux.findViewById(R.id.accordion_msg);
String msg_text = dbStructure.getMsg();
if(msg_text.contains("href=\"")) {
    String[] msg_aux = msg_text.split("<a href=\"");
    if (!msg_aux[1].toLowerCase().startsWith("http"))
        msg_aux[1] = "href=\"http://" + msg_aux[1];
    else
        msg_aux[1] = "href=\"" + msg_aux[1];
    msg_text = msg_aux[0] + msg_aux[1];
}
msg.setText(Html.fromHtml(msg_text));
msg.setTypeface(tF);
msg.setTextColor(Color.DKGRAY);
msg.setMovementMethod(LinkMovementMethod.getInstance());

谢谢。

编辑 代码,这些行:

else
    msg_aux[1] = "href=\"" + msg_aux[1];