本文介绍了设置自动链接属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在阵列某些URL时,我的文字点击查看需要打开网页,但即时得到错误我的code为
的LinearLayout L =新的LinearLayout(本);
l.setOrientation(LinearLayout.VERTICAL);
的String [] = textArray {www.google.co.in,www.gmail.com,www.facebook.com};
INT长度= textArray.length;
的LinearLayout布局=新的LinearLayout(本);
的setContentView(布局);
layout.setOrientation(LinearLayout.VERTICAL);
的for(int i = 0; I<长度;我+ +)
{
TextView的电视=新的TextView(getApplicationContext());
tv.setText(textArray [I]);
layout.addView(电视);
Linkify.addLinks(电视,Linkify.WEB_URLS);
tv.setMovementMethod(LinkMovementMethod.getInstance())
12-20 16:08:38.623: E/InputEventReceiver(2170): Exception dispatching input event.
12-20 16:08:38.623: E/MessageQueue-JNI(2170): Exception in MessageQueue callback: handleReceiveCallback
12-20 16:08:38.804: E/MessageQueue-JNI(2170): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:944)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.text.style.URLSpan.onClick(URLSpan.java:62)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.widget.TextView.onTouchEvent(TextView.java:7397)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.View.dispatchTouchEvent(View.java:7239)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.View.dispatchPointerEvent(View.java:7419)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.os.MessageQueue.nativePollOnce(Native Method)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.os.MessageQueue.next(MessageQueue.java:125)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.os.Looper.loop(Looper.java:124)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-20 16:08:38.804: E/MessageQueue-JNI(2170): at dalvik.system.NativeStart.main(Native Method)
12-20 16:08:38.804: D/AndroidRuntime(2170): Shutting down VM
12-20 16:08:38.813: W/dalvikvm(2170): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-20 16:08:38.913: E/AndroidRuntime(2170): FATAL EXCEPTION: main
12-20 16:08:38.913: E/AndroidRuntime(2170): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:944)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.ContextImpl.startActivity(ContextImpl.java:931)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.content.ContextWrapper.startActivity(ContextWrapper.java:284)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.text.style.URLSpan.onClick(URLSpan.java:62)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.widget.TextView.onTouchEvent(TextView.java:7397)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.View.dispatchTouchEvent(View.java:7239)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.View.dispatchPointerEvent(View.java:7419)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.os.MessageQueue.nativePollOnce(Native Method)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.os.MessageQueue.next(MessageQueue.java:125)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.os.Looper.loop(Looper.java:124)
12-20 16:08:38.913: E/AndroidRuntime(2170): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-20 16:08:38.913: E/AndroidRuntime(2170): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 16:08:38.913: E/AndroidRuntime(2170): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-20 16:08:38.913: E/AndroidRuntime(2170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-20 16:08:38.913: E/AndroidRuntime(2170): at dalvik.system.NativeStart.main(Native Method)
解决方案
In addition: if you show links in adapter in fragment, do not create it like this
adapter = new ListAdapter(getActivity().getApplicationContext(),mStrings,dispWidth,dispHeight);
instead call
adapter = new ListAdapter(getActivity(),mStrings,dispWidth,dispHeight);
adapter works fine in both cases, but links work only in last one.
这篇关于设置自动链接属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!