更新 MergeAdapter 的内容
我有一个非常漂亮的 MergeAdapter,其中包含一堆自定义视图和一些自定义 ListAdapter。此 MergeAdapter 驱动一个 ListActivity,该 ListActivity 显示每 x 秒更新一次的内容。
目前,我只是创建一个新的 MergeAdapter,创建并添加所有自定义视图(其中包括一些 ImageView) - 并在我的活动中的 ListView 上调用 setAdapter。
大约 10 分钟的更新后,我耗尽了堆空间并崩溃了。
最终因为添加了新的 ImageView,并引发了以下异常:
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
使用更简单的适配器(如 ArrayAdapter),我只需更新数据集,然后调用
notifyDataSetChanged()
适配器。
是否有类似/推荐的方法来“更新” MergeAdapter?或者我应该遍历潜在复杂的 MergeAdapter 的内容并更新单个视图?
I have a pretty nifty MergeAdapter that contains a bunch of custom views and some custom ListAdapters. This MergeAdapter drives a ListActivity that displays content that get's updated every x seconds.
Currently I just create a new MergeAdapter, create and add all of my custom views (and this includes a few ImageViews) - and call setAdapter on the ListView in my activity.
After about 10 minutes of updates I run out of heap space and crash.
Ultimately because a new ImageView is added, and the following exception is thrown:
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
With simpler adapters (like ArrayAdapter), I would just update the data set, and call
notifyDataSetChanged()
on the adapter.
Is there a similar/recommended approach for "updating" a MergeAdapter? Or should I be walking the contents of a potentially complex MergeAdapter and updating individual Views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
notifyDataSetChanged()
有效,据我所知。当前的MergeAdapter
具有将其内部的ListAdapters
的任何更改传递到MergeAdapter
中已注册的更改兴趣的代码。这可能还没有经过足够的测试,所以如果您有一个示例应用程序来演示其他情况,请发布指向它的链接或将其发送给我(提及这个SO问题)。notifyDataSetChanged()
works, AFAIK. The currentMergeAdapter
has the code to ripple any changes fromListAdapters
inside it to whatever has registered interests in changes in theMergeAdapter
. This probably has not been tested enough, so if you have a sample app that demonstrates otherwise, post a link to it or send it to me (mention this SO question).