1

EDIT: After spending almost all day on this OutOfMemory Error I was getting, turns out I simply wasnt advancing a cursor. However, I still wish to obtain an answer for my question below. To clarify, my question is:

Is it faster to make a custom adapter for a listview that hooks directly into the database to retrieve the data, or should an arraylist of that data be made first and then passed into a default arrayadapter?

I am currently working on an application and as a part of one of its functions I need to be able to take data from an internal database and display parts of it in various listviews. These listviews are all linked together in a ViewFlipper to make it easy to move between the views. I am working with about 5000 values maximum at once. (That is the stress size for the data set that I am tasked to work with).

Should I write a custom adapter that directly links to the database and extracts the values, or is there a better way to go about this? I tried to create a sort of wrapper class for the database that would extract all necessary data from the database and place it into a POJO but i keep getting OutOfMemory exceptions (5 string values * 5000 rows = 25000 strings doesnt seem to be nicely accepted in my case).

pogo2065
  • 226
  • 1
  • 3
  • 14

1 Answers1

0

Not with the same amount of values, 5000 but I had a similar problem. I ended up using a private arrayList on a ListAdapter, the list will contain only partial lists, for example 100 items. Your cursor can initially contain the values to fill the firsts 100 items and when you scroll down looking for more items you can launch another cursor to retreive the next 50 items. Controlling a range of 100-150 items at your arrayList by adding/removing new/old items and refreshing the adapter.

I vote up your question because maybe someone find a better way to do it and I would like to know as well.

AlexBcn
  • 2,450
  • 2
  • 17
  • 28
  • Apparently the best way to manage this is to use a CursorAdapter. Still not quite sure how to mange this tho - if I find a more concrete answer ill post it here. EDIT: Reference: http://developer.android.com/reference/android/widget/CursorAdapter.html – pogo2065 Jun 12 '13 at 13:49