是否可以使用linkify使用模式进行调用?我想在textview中显示文本“call store”。当我点击textview时需要拨打给定的号码。为此我试过下面的代码。
Linkify.addLinks(callStoreTxt ,pattern,"9465789002" );
这里callStoretxt是我的textview的名字。 但它崩溃了。无论如何要做到这一点? 编辑:我的崩溃logcat
07-11 15:11:02.361: E/AndroidRuntime(31906): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=seethalakshmi.may2009@gmail.comS (has extras) }
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.app.Activity.startActivityForResult(Activity.java:3190)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.support.v4.app.FragmentActivity.startActivityForResult(Unknown Source)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.app.Activity.startActivity(Activity.java:3297)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.text.style.URLSpan.onClick(URLSpan.java:62)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.widget.TextView.onTouchEvent(TextView.java:8344)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.View.dispatchTouchEvent(View.java:5541)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
07-11 15:11:02.361: E/AndroidRuntime(31906): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1912)
07-11 15:11:02.361: E/AndroidRuntime(31906): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
07-11 15:11:02.361: E/AndroidRuntime(31906): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.View.dispatchPointerEvent(View.java:5721)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewRootImpl.handleMessage (ViewRootImpl.java:2466)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.os.Looper.loop(Looper.java:137)
07-11 15:11:02.361: E/AndroidRuntime(31906): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-11 15:11:02.361: E/AndroidRuntime(31906): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 15:11:02.361: E/AndroidRuntime(31906): at java.lang.reflect.Method.invoke(Method.java:511)
07-11 15:11:02.361: E/AndroidRuntime(31906): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-11 15:11:02.361: E/AndroidRuntime(31906): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-11 15:11:02.361: E/AndroidRuntime(31906): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
您可以使用HTML(使用'tel'协议)来执行此操作:
TextView textView = new TextView(this);
textView.setText(Html.fromHtml("<a href='tel:9465789002'>Call store</a>"));
textView.setMovementMethod(LinkMovementMethod.getInstance());
setMovementMethod()
启用TextView中的链接。