【问题标题】:Problem when click to HTML links inside a ListView?单击 ListView 内的 HTML 链接时出现问题?
【发布时间】:2010-07-15 07:25:13
【问题描述】:

我将下面的代码用于我的列表视图和文本视图。

代码:

textcontent.setText(Html.fromHtml(item.get_text()));
textcontent.setAutoLinkMask(Linkify.WEB_URLS);

XML:

<TextView
                android:id="@+id/txtview"
                android:autoLink="web"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="put your link here"/>

链接看起来像 url,我可以点击它,但它会生成此异常

android.util.AndroidRuntimeException: 从外部调用 startActivity() 一个活动上下文需要 FLAG_ACTIVITY_NEW_TASK 标志。

知道如何解决这个问题吗?

【问题讨论】:

  • 我在主 Activity 类之外的其他类中有列表适配器,然后我从主 Activity 类的列表适配器类创建对象并将上下文传递给它,这可能是问题的原因?

标签: android


【解决方案1】:

不要将应用程序上下文传递给 ListAdapter 构造函数。而是传递您的主要活动。

ListAdapter flareAdapter = new ListAdapter(LayoutInflater.from(activity), Items);

即使您在其他类中创建适配器,您也应该传递主活动引用。

【讨论】:

  • 感谢您的提示,这就是我所做的,它可以工作 Context aContext ;一个上下文=这个; ListAdapterflareAdapter = new ListAdapter(LayoutInflater.from(aContext), Items);
  • 非常感谢。我只是将 Activity 作为上下文传递给适配器。新的 ListAdapter(this,etc..)
【解决方案2】:

您确定点击导致的异常不是您想要启动的吗?

正如我所见,您需要将标志添加到意图中(但不确定您的意图是什么)

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

【讨论】:

  • 如果是这样,也许可以从异常日志中给我们更多信息,让我们看看堆栈跟踪。
  • 我在主 Activity 类之外的其他类中有列表适配器,然后我从主 Activity 类的列表适配器类创建对象并将上下文传递给它,这可能是问题的原因?
  • ListAdapterflareAdapter = new ListAdapter(LayoutInflater .from(getApplicationContext()), Items);
猜你喜欢
  • 1970-01-01
  • 2015-04-07
  • 2020-07-09
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多