1

I have a SQLite database and I'm getting a ListView from the database through a SimpleCursorAdapter. This is the existing code:

Cursor c = mDatabase.query(
            "database",
            bla = new String[]{
                    "_id",
                    "title",
                    "message",
                    "time",
                    "date",
                    "done"
            },
            null, null, null, null, null);
    startManagingCursor(c);

    SimpleCursorAdapter listAdapter =
            new SimpleCursorAdapter(this,
                    R.layout.list_item, c,
                    new String[]{"title", "message", "time", "date"},
                    new int[]{R.id.txtv_title, R.id.txtv_message, R.id.txtv_time, R.id.txtv_date}
            );
    setListAdapter(listAdapter);

This works as intended and I'm getting my ListView. Now I want that if the "done" field in my database contains the string "false" (instead of "true" ...), this row doesn't get into the ListView.

How can I do this? Thanks in advance!

4

1 回答 1

1

This is more a SQL then Android-related. What you're looking for is a Where-clause:

String query = "SELECT _id, title, message, time, date, done "+
"FROM database "+
"WHERE done = 'true' "+
"ORDER BY date";

To send this Query to your SQLite Database, you can use the rawQuery()-method:

final Cursor c = db.rawQuery(query, null);
于 2011-04-20T17:40:16.943 回答