简体   繁体   中英

Android and loading a listview from a sqlite database

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 dochttp://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

You're passing a list of Ticket s to the <String> adapter. Try to change it:

setListAdapter(new ArrayAdapter<Ticket>(this, R.layout.main.list, tickets));

You should use a ArrayAdapter when show data from a database in a ListView. Use a CursorAdapter (eg 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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM