0

我有一个数据库,我想从中查询并仅显示具有一种类似字段的数据。假设所有行中都有一天(星期一到太阳)...我想显示所有具有星期一的行作为一天...我已经使用 SimpleCursorAdapter 来显示我的数据库中的所有行...基本上,我想知道如何在 SimpleCursorAdapter 中查询以显示数据行,只说星期一是一天...

任何帮助表示赞赏... :)

以下代码使我能够显示数据库中的所有数据...

    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.testlayout2);
     listContent = (ListView)findViewById(android.R.id.list);//.id..list);
    mDB = new DataSource(this);
    mDB.open();

    cursor = mDB.queueAll();
    String[] from = new String[]{
            MySQLiteHelper.KEY_START, MySQLiteHelper.KEY_END,
            MySQLiteHelper.KEY_SUBJECT, MySQLiteHelper.KEY_LOC,
            MySQLiteHelper.KEY_TEACHER };
    int[] to = new int[] {R.id.tvStart, R.id.tvEnd,
            R.id.tvSub, R.id.tvLoc, R.id.tvTeacher };


            cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor,
            from, to);

        listContent.setAdapter(cursorAdapter);
        listContent.setOnItemClickListener(listContentOnItemClickListener);
    }

}

我希望查询是这样的..

  Cursor cursor = db.query(table, null, "day like " + "'%Monday%'",null, 
                                 null, null, null);

明白了……抱歉给你添麻烦了。请告诉我我哪里出了问题..我在代码中做了这个来查询日期并按时间升序排序..

 public Cursor queryDay(String days) {
    Cursor cursor = mDatabase.query(DATABASE_TABLE, mAllColumns, "day like " + 
                     days, null, null, null, Database.KEY_START + " ASC");
    if (cursor.moveToNext()) {
        return cursor;
    }
    return cursor;
}

但是,我收到此错误,

   android.database.sqlite.SQLiteException: no such column: Thursday: , 
   while compiling: SELECT _id, day,start_time, end_time, sub, location, 
   teacher FROM subjectTable WHERE day like Thursday ORDER BY start_time ASC

我这样称呼这个..

 Cursor cursor = mDB.queryDay("Thursday");
 startManagingCursor(cursor);
4

2 回答 2

2

您不查询适配器,而是查询数据库,它提供了一个游标,您将其倒入列表适配器中。

mDbHelper.rawQuery("SELECT * FROM your_table WHERE day_column = 'Monday');
于 2012-05-18T00:04:04.997 回答
0

这解决了问题的第二部分..

    public Cursor queryDay(String days) {
    Cursor cursor = mDatabase.query(DATABASE_TABLE, mAllColumns, "day like " 
     + "'" + days + "'", null,null, null, Database.KEY_START + " ASC");
    if (cursor.moveToNext()) {
        return cursor;
    }
    return cursor;
}
于 2012-05-18T10:22:35.980 回答