My app uses a simple SQLite database. Everything works fine I can now present a Toast with a chosen row from the return query using:
{
//etc etc etc...
c.movetofirst();
DisplayTitle(c);
}
public void DisplayTitle(Cursor c)
{
Toast.makeText(main.this,
"id: " + c.getString(0) + "\n" +
"reg: " + c.getString(1) + "\n" +
"type: " + c.getString(2) + "\n",
Toast.LENGTH_LONG).show();
}
I want to prsent all the data in the cursor to the screen using a view but I am not sure how to go about this. Which view should I use? I just wnt a simple looking grid representation which allows me to scroll through each row in the cursor
Thanks in advance.
There are several ways if you are working with a
Cursor, for example see the “moveTo” related methods, here’s an example:This assumes
Itemis a data class that has a constructor with threeStringparameters. Going with your code, id, reg, and type. Usually column 0 will be a numeric ID (not getString, but SQLite uses “manifest typing” so it will sort of dyna-type a String/Long from column 0 — you may want to AUTOINCREMENT and use getLong there though).One you have a collection of items, you can do anything you want with them to display them. If you want a scrolling/selectable list, then
ListViewis an excellent choice. And, you can back it with aCursorAdapter.Here’s an example of a
ListViewthat is populated by aCursorAdapterfrom an open source project: http://code.google.com/p/and-bookworm/source/browse/trunk/src/com/totsp/bookworm/Main.java (see the innerBookCursorAdapterclass, it should get you pointed in the right direction).