I am new to android and after going through many tutorials I still can’t get things.
I have created a database and is now reading this database.
This database and 3 columns All three string type.
Now I want to show this database using ListView.I have this ListView
created with id “listDatabaseItems” in R.layout.viewDatabase
Currently my code is:
Cursor c = sqliteDatabase.query(MY_DATABASE_TABLE, null, null, null, null, null, null);
int firstNameColumn = c.getColumnIndex("name_column");
int protectedColumn = c.getColumnIndex("protected_id_column");
ArrayList<String> results = new ArrayList<String>();
int i = 0;
c.moveToFirst();
do {
i++;
String firstName = c.getString(firstNameColumn);
String protectedID = c.getString(protectedColumn);
results.add(firstName + protectedID); // NEED TO add here
} while (c.moveToNext());
sqliteDatabase.close();
Please tell me what changes I do and how can I show my database in ListView.
Best Regards.
Make a
Adapteradd yourListArrayvalues to it, and thensetAdapterto your listview simple,After your code, add just two lines,
Also, your question sounds basic for android So just look at these links..
SimpleCursorAdapters and ListViews
Android SQLite Database and ContentProvider – Tutorial
Filling the Layout with Data