问题
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