Android and loading a listview from a sqlite database

Issue

I’m creating an app which uses a Data Access Object class to load values into a Serializable object.

How do I do the following.

  • Find the ListView object from the layout.
  • Load the serialized list into the ListView

i’m reading the following doc http://developer.android.com/resources/tutorials/views/hello-listview.html

but i’m getting this error when i’m trying to follow that code but using the serialized list:

cannot find symbol
  [javac] symbol  : constructor ArrayAdapter(

i have this at the top of my file too

import android.widget.ArrayAdapter;

I’m trying to target 2.1 and above.

this is my code as it stands

http://pastie.org/1976415

Solution

You should use a ArrayAdapter when show data from a database in a ListView. Use a CursorAdapter (e.g. SimpleCursorAdapter) instead. With a cursor and a CursorAdapter you will get much better performance as items get only read from the database when they are needed (e.g. the user scrolls the list).

When you use an ArrayAdapter you have do load all items in advance which is unnecessary as you might not need all of them. So using a Cursor and a CursorAdapter will give you better performance and reduce the memory usage.

Check this blog post for a tutorial.

Answered By – Flo

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published