Android的 - Linkify问题 [英] Android - Linkify Problem

查看:230
本文介绍了Android的 - Linkify问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎有与我使用我的自定义适配器的linkify麻烦。出于某种原因,我收到下面的堆栈跟踪,当我点击其中一个链接:

I seem to be having trouble with the linkify I am using in my Custom Adapter. For some reason I recieve the following stack track when I click on one of the links:

06-07 20:49:34.696: ERROR/AndroidRuntime(813): Uncaught handler: thread main exiting due to uncaught exception
06-07 20:49:34.745: ERROR/AndroidRuntime(813): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.app.ApplicationContext.startActivity(ApplicationContext.java:550)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:248)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.text.style.URLSpan.onClick(URLSpan.java:62)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:216)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.widget.TextView.onTouchEvent(TextView.java:6560)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.View.dispatchTouchEvent(View.java:3709)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
06-07 20:49:34.745: ERROR/AndroidRuntime(813):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)

下面是code被称之为

    TextView bot = new TextView( c );
    bot.setText(li.getBottomText());
    bot.setTextColor(Color.BLACK);
    bot.setTextSize(12);
    bot.setPadding(50, 35, 0, 10);
    Linkify.addLinks(bot, Linkify.ALL);
    rL.addView(bot,ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

我明白什么是错误的说法,但我不知道如何解决它。有没有人有什么想法? 在此先感谢您的帮助

推荐答案

原来,这个问题的答案是简单了很多,比我原本以为。问题是,当我路过的背景下,以我的自定义适配器,我路过的 getApplicationContext()这是不一样的使用标识。

Turns out the answer to this is a lot simpler than I had originally thought. The problem was that when I was passing the context to my custom adapter I was passing the getApplicationContext() which is not the same as using the this identifier.

不正确的方法

Context mContext = getApplicationContext();
CustomAdapter mAdapter = new CustomAdapter( 
                mContext,
                itemList); 

正确的方法

CustomAdapter mAdapter = new CustomAdapter( 
                this,
                itemList); 

这篇关于Android的 - Linkify问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆