0

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?

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
NPike
  • 13,136
  • 12
  • 63
  • 80

1 Answers1

0

Is there a similar/recommended approach for "updating" a MergeAdapter?

notifyDataSetChanged() works, AFAIK. The current MergeAdapter has the code to ripple any changes from ListAdapters inside it to whatever has registered interests in changes in the MergeAdapter. 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).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I am using Custom Cursor adapters for my single listview .I try to merge two cursor adapter into one single listview. I want to refresh listview after result come from server.But mergeAdapter does not refresh. – BABU K May 13 '14 at 12:35
  • 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(); – BABU K May 13 '14 at 12:37
  • @CommonsWare: Im using MergeAdapter to merge different Views and SimpleCursorAdapters. As you said notifyDataSetChanged updates any ListAdapters. But is there a workaround to update the Views? Please help. – abhijit.mitkar Oct 01 '14 at 13:18
  • 1
    @abhijit.mitkar: Call methods on your `Views` to change what they look and behave like. There is no means in `MergeAdapter` to replace them, though that is something that could be added. – CommonsWare Oct 01 '14 at 13:21