开发者

Database to ListView - Filter out entries

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!


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜