我正在尝试为Twitter Feed添加一个库,我已经完成了大部分工作,但是我遇到了一个问题,我的文本中的链接在点击时崩溃了,我想知道是否有人可以指出我正确的方向来解决这个问题。
我的推文的主要文本字段在XML中定义为:
<TextView
android:textColor="@android:color/black"
android:id="@+id/TweetUITweetTextTextView"
android:padding="@dimen/tweetTextPadding"
android:layout_toRightOf="@+id/TweetUIUserProfileImageView"
android:layout_below="@+id/TweetUIUsernameTextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:linksClickable="true"
android:autoLink="web"
android:text="@null" />
这位于相对布局的内部,我将其扩展为自定义的“TweetView”类。
TweetView采用一个Tweet对象,它基本上是一组包含从JSON查询解析的信息的字符串,并设置这些字符串(在这种情况下,来自Tweet的主要文本带有锚标记和来自URL元数据的东西)使用这个文本视图的Twitter JSON feed):
if( tweet.tweetText != null && tweet.tweetText != "" )
tweetTextTextView.setText( Html.fromHtml( tweet.tweetTextWithLinks ) );
else
tweetTextTextView.setText( "" );
至于我在崩溃时的错误堆栈,我有这个:
05-30 14:42:22.206: E/InputEventReceiver(22150): Exception dispatching input event.
05-30 14:42:22.206: E/MessageQueue-JNI(22150): Exception in MessageQueue callback: handleReceiveCallback
05-30 14:42:22.216: E/MessageQueue-JNI(22150): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.app.ContextImpl.startActivity(ContextImpl.java:944)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.text.style.URLSpan.onClick(URLSpan.java:62)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.widget.TextView.onTouchEvent(TextView.java:7536)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.View.dispatchTouchEvent(View.java:7246)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-30 14:42:22.216: E/MessageQueue-JNI(22150): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
.....
谢谢!
答案 0 :(得分:3)
您可能在适配器中传递了“错误”的上下文。例如。应用程序上下文而不是活动上下文。