Clickable Links inside listview

点点圈 提交于 2019-12-07 11:46:18

问题


List view clickable link poblem.

I'm using the following code inside the getView() to generate a clickable link in a listview.

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

This code works fine on a textview which is not in a listview but when i use it for a textview within a list view the following exception is raised on clicking the link.

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

回答1:


Got the answer here. I just had to change the constructor call from

CustomAdapter mAdapter = new CustomAdapter( mContext, itemList);

to

CustomAdapter mAdapter = new CustomAdapter( this, itemList);



回答2:


   TextView textView2 = (TextView)findViewById( R.id.TextView2 );
   SpannableStringBuilder ssb = new SpannableStringBuilder( http://google.com" );
   textView2.setText( ssb, BufferType.SPANNABLE );
   Linkify.addLinks( textView2, Linkify.WEB_URLS );

     Try this one....



回答3:


I had the problem that the ApplicationContext was used for inflating the views. Changed it to ActivityContext, now it works!



来源:https://stackoverflow.com/questions/10277474/clickable-links-inside-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!