



This requires us to use a SQLiteOpenHelper for persistence as described here or an ORM that provides access to the underlying database. In order to use a CursorAdapter, we need to query a SQLite database and get back a Cursor representing the result set. Finally, we override the bindView method, which is used to bind all data to a given view to populate the template content for the item. Next, we override the newView method, which is used to inflate a new view template. The naive approach to this (without any view caching) looks like the following: public class TodoCursorAdapter extends CursorAdapter įirst, we define a constructor that passes the cursor and context to the superclass. To do this we need to override the newView method and the bindView method. Next, we need to define the adapter to describe the process of projecting the Cursor's data into a View. We can simply create an XML layout template in res/layout/item_todo.xml, representing a particular cursor row: Defining the Adapter When we want to display a series of items into a list, using a custom representation of the items, we need to use our own custom XML layout template for each item. To create this database table, we would use SQLite persistence or an ORM that allows us to define objects mapped to tables. In this case, we will define a database table called todo_items for a collection of todo items with a string body and an integer priority. Using a Custom CursorAdapter Defining our Tableįirst, we need to define a table within the database from which we will load our cursor.

In Android development, any time you want to show a vertical list of items you will want to use a ListView which is populated using an Adapter to a data source.
