android ︰ 自动链接 ="电话"不工作里面fragment

发布时间: 2016/9/16 23:55:28
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有 activity 使用 SlidingTabLayout 创建的两个选项卡和 ViewPager 。每个选项卡是 fragment 与不同的布局。这两种版式但是包含类似的 textviews 链接到一个电话号码,使用自动链接 ="电话"。

<TextView android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:id="@+id/contact"
 android:text="+91-0000000000"
 android:autoLink="phone"/>

问题︰ 当我点击 textview tab1(first fragment ),在它完美的作品,并链接到电话拨号程序。然而做相同的 tab2(second fragment ) 应用程序崩溃。

错误 log :

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
            at android.app.ContextImpl.startActivity(ContextImpl.java:1234)
            at android.app.ContextImpl.startActivity(ContextImpl.java:1221)
            at android.content.ContextWrapper.startActivity(ContextWrapper.java:322)
            at android.text.style.URLSpan.onClick(URLSpan.java:62)
            at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:217)
            at android.widget.TextView.onTouchEvent(TextView.java:7992)
            at android.view.View.dispatchTouchEvent(View.java:8393)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2431)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2173)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2317)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1692)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2790)
            at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:59)
            at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:59)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2278)
            at android.view.View.dispatchPointerEvent(View.java:8583)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4060)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3926)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3483)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3536)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3502)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3612)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImp

我哪里做错了?

解决方法 1:

没有一个以上的答案为我工作。这里是如何修复它︰

我的选项卡fragment了里面显示的自动链接的自定义 ArrayAdapters。要初始化 adaptercontext 通过了

getActivity().getApplicationContext()

我改变了 contextgetActivity()

官方微信
官方QQ群
31647020