列表视图内的可点击链接

2023-12-20

列表视图可点击链接问题。

我在 getView() 中使用以下代码在列表视图中生成可单击的链接。

myTextView.setMovementMethod(LinkMovementMethod.getInstance());
String linkText = "<a href=\"http://www.google.com\">Google</a>";
myTextView.setText(Html.fromHtml(linkText));

此代码在不在列表视图中的文本视图上运行良好,但是当我将其用于列表视图中的文本视图时,单击链接时会引发以下异常。

AndroidRuntimeException: Calling startActivity() from outside of an Activity
context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

得到了答案here https://stackoverflow.com/questions/2993112/android-linkify-problem/。我只需要将构造函数调用更改为

CustomAdapter mAdapter = new CustomAdapter( mContext, itemList);

to

CustomAdapter mAdapter = new CustomAdapter( this, itemList);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

列表视图内的可点击链接 的相关文章

随机推荐