Android populate listview with cursor?

There are several ways if you are working with a Cursor for example see the "moveTo" related methods, here's an example: Set items = new HashSet(c.getCount()); if (c.moveToFirst()) { do { Item I = new Item(select(c. GetString(0), c. GetString(1), c.

GetString(2)); set. Add(i); } while (c.moveToNext()); } if (!c.isClosed()) { c.close(); } This assumes Item is a data class that has a constructor with three String parameters. 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 ListView is an excellent choice. And, you can back it with a CursorAdapter Here's an example of a ListView that is populated by a CursorAdapter from an open source project: http://code.google.com/p/and-bookworm/source/browse/trunk/src/com/totsp/bookworm/Main.java (see the inner BookCursorAdapter class, it should get you pointed in the right direction).

There are several ways if you are working with a Cursor, for example see the "moveTo" related methods, here's an example: Set items = new HashSet(c.getCount()); if (c.moveToFirst()) { do { Item I = new Item(select(c. GetString(0), c. GetString(1), c.

GetString(2)); set. Add(i); } while (c.moveToNext()); } if (!c.isClosed()) { c.close(); } This assumes Item is a data class that has a constructor with three String parameters. 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 ListView is an excellent choice.

And, you can back it with a CursorAdapter. Here's an example of a ListView that is populated by a CursorAdapter from an open source project: http://code.google.com/p/and-bookworm/source/browse/trunk/src/com/totsp/bookworm/Main.java (see the inner BookCursorAdapter class, it should get you pointed in the right direction).

I already have a method for populating the cursor with all rows in the table, what I am asking for is how to present this to the screen. I want to use a view to present all data in the cursor onto the screen. Sorry If I was not very clear!

– brux Nov 21 '10 at 14:05 I updated the answer, after you updated the question ;). If you want a simple looking scrollable "grid," and you already have the Cursor, then ListView/CursorAdapter is the ticket. – Charlie Collins Nov 21 '10 at 14:15 Thanks you for the link im taking a look – brux Nov 21 '10 at 14:18.

If you want a scrolling/selectable list, then ListView is an excellent choice. And, you can back it with a CursorAdapter. Here's an example of a ListView that is populated by a CursorAdapter from an open source project: http://code.google.com/p/and-bookworm/source/browse/trunk/src/com/totsp/bookworm/Main.java (see the inner BookCursorAdapter class, it should get you pointed in the right direction).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions