【问题标题】:Updating the contents of a MergeAdapter更新 MergeAdapter 的内容
【发布时间】:2011-08-29 20:29:24
【问题描述】:

我有一个非常漂亮的 MergeAdapter,其中包含一堆自定义视图和一些自定义 ListAdapter。这个 MergeAdapter 驱动一个 ListActivity,它显示每 x 秒更新一次的内容。

目前我只是创建一个新的 MergeAdapter,创建并添加我所有的自定义视图(其中包括一些 ImageView) - 并在我的 Activity 中调用 ListView 上的 setAdapter。

大约 10 分钟的更新后,我用完了堆空间并崩溃了。

最终因为添加了新的ImageView,抛出了如下异常:

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

使用更简单的适配器(如 ArrayAdapter),我只需更新数据集,然后调用

notifyDataSetChanged()

在适配器上。

“更新” MergeAdapter 是否有类似/推荐的方法?或者我应该遍历可能复杂的 MergeAdapter 的内容并更新单个视图?

【问题讨论】:

    标签: android commonsware-cwac


    【解决方案1】:

    是否有类似/推荐的方法来“更新” MergeAdapter?

    notifyDataSetChanged() 工作,AFAIK。当前的MergeAdapter 具有代码,可以将其中的ListAdapters 的任何更改影响到对MergeAdapter 的更改感兴趣的任何内容。这可能还没有经过足够的测试,所以如果您有一个示例应用程序可以演示,请发布指向它的链接或将其发送给我(提及这个 SO 问题)。

    【讨论】:

    • 我正在为我的单个列表视图使用自定义光标适配器。我尝试将两个光标适配器合并到一个列表视图中。我想在结果来自服务器后刷新列表视图。但是 mergeAdapter 不刷新。
    • FeedQuestionCursor = ctx.getContentResolver().query(FeedQuestionProvider.FEED_QUESTION_URI, null, null, null, null); QuestionAdapter.changeCursor(FeedQuestionCursor); QuestionAdapter = new FeedQuestionCursorAdapter(getActivity(), FeedQuestionCursor); lv_earn_question.invalidate(); // QuestionAdapter.notifyDataSetChanged(); ((BaseAdapter) QuestionAdapter).notifyDataSetChanged();
    • @CommonsWare:我使用 MergeAdapter 来合并不同的视图和 SimpleCursorAdapter。正如您所说,notifyDataSetChanged 会更新任何 ListAdapters。但是有更新视图的解决方法吗?请帮忙。
    • @abhijit.mitkar:在您的Views 上调用方法来更改它们的外观和行为。 MergeAdapter 没有办法替换它们,尽管可以添加。
    猜你喜欢
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 2023-03-15
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多