gpt4 book ai didi

java - android:autoLink ="phone"在 fragment 内不起作用

转载 作者:行者123 更新时间:2023-12-01 10:28:32 26 4
gpt4 key购买 nike

我有一个 Activity ,其中有两个使用 SlidingTabLayout 和 ViewPager 创建的选项卡。每个选项卡都是具有不同布局的 fragment 。然而,这两种布局都包含类似的 TextView ,可以使用 autolink="phone"链接到电话号码。

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

问题:当我点击 tab1(第一个 fragment )中的 TextView 时,它工作正常并链接到手机的拨号器。但是,在 tab2(第二个 fragment )中执行相同操作会使应用程序崩溃。

错误日志:

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

我哪里出错了?

最佳答案

以上答案都不适合我。这是我修复它的方法:

我的选项卡 fragment 具有自定义 ArrayAdapter,其中显示自动链接。为了初始化适配器,传递的上下文是

getActivity().getApplicationContext()

我将上下文更改为getActivity()

关于java - android:autoLink ="phone"在 fragment 内不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35221792/

26 4 0
文章推荐: Xcode - 找不到 'openssl/opensslconf.h' 文件
文章推荐: java - 当 List deviceList 更改时更新 JavaFX ListView